allow Motif hints to be smaller than expected; GLUT for example seems to

2002-08-10  Havoc Pennington  <hp@pobox.com>

	* src/xprops.c (meta_prop_get_motif_hints): allow Motif hints to
	be smaller than expected; GLUT for example seems to set a smaller
	struct. #89841

	* src/window.c (update_mwm_hints): use g_free on motif hints as we
	don't use the XGetWindowProperty return directly anymore
This commit is contained in:
Havoc Pennington 2002-08-10 18:12:36 +00:00 committed by Havoc Pennington
parent c540438b91
commit 02bcf06809
3 changed files with 30 additions and 7 deletions

View File

@ -1,3 +1,12 @@
2002-08-10 Havoc Pennington <hp@pobox.com>
* src/xprops.c (meta_prop_get_motif_hints): allow Motif hints to
be smaller than expected; GLUT for example seems to set a smaller
struct. #89841
* src/window.c (update_mwm_hints): use g_free on motif hints as we
don't use the XGetWindowProperty return directly anymore
2002-08-10 Havoc Pennington <hp@pobox.com> 2002-08-10 Havoc Pennington <hp@pobox.com>
* src/window.c (meta_window_free): be sure window is * src/window.c (meta_window_free): be sure window is

View File

@ -4385,7 +4385,7 @@ update_mwm_hints (MetaWindow *window)
else else
meta_verbose ("Functions flag unset\n"); meta_verbose ("Functions flag unset\n");
meta_XFree (hints); g_free (hints);
recalc_window_features (window); recalc_window_features (window);
} }

View File

@ -166,14 +166,17 @@ meta_prop_get_motif_hints (MetaDisplay *display,
gulong bytes_after; gulong bytes_after;
MotifWmHints *hints; MotifWmHints *hints;
gulong n_items; gulong n_items;
int real_size, max_size;
#define EXPECTED_ITEMS sizeof (MotifWmHints)/sizeof (gulong) #define MAX_ITEMS sizeof (MotifWmHints)/sizeof (gulong)
*hints_p = NULL; *hints_p = NULL;
hints = NULL;
n_items = 0;
meta_error_trap_push (display); meta_error_trap_push (display);
if (XGetWindowProperty (display->xdisplay, xwindow, xatom, if (XGetWindowProperty (display->xdisplay, xwindow, xatom,
0, EXPECTED_ITEMS, 0, MAX_ITEMS,
False, AnyPropertyType, &type, &format, &n_items, False, AnyPropertyType, &type, &format, &n_items,
&bytes_after, (guchar **)&hints) != Success || &bytes_after, (guchar **)&hints) != Success ||
type == None) type == None)
@ -185,14 +188,25 @@ meta_prop_get_motif_hints (MetaDisplay *display,
if (meta_error_trap_pop (display) != Success) if (meta_error_trap_pop (display) != Success)
return FALSE; return FALSE;
if (type == None || n_items != EXPECTED_ITEMS) if (type == None || n_items <= 0)
{ {
meta_verbose ("Motif hints had unexpected type or n_items\n"); meta_verbose ("Motif hints had unexpected type or n_items\n");
XFree (hints); XFree (hints);
return FALSE; return FALSE;
} }
*hints_p = hints; g_assert (hints != NULL);
/* The issue here is that some old crufty code will set a smaller
* MotifWmHints than the one we expect, apparently. I'm not sure of
* the history behind it. See bug #89841 for example.
*/
*hints_p = g_new0 (MotifWmHints, 1);
real_size = n_items * sizeof (gulong);
max_size = MAX_ITEMS * sizeof (gulong);
memcpy (*hints_p, hints, MIN (real_size, max_size));
XFree (hints);
return TRUE; return TRUE;
} }