Re: bug in gdk_gc_new_with_values




Paul Barton-Davis <pbd@Op.Net> writes:

> Illustration:
> 
> 	... GtkWidget c; .... /* created elsewhere */
> 	... GtkStyle style; ... /* set up elsewhere */
> 
>        GdkGC *style_gc;
>        GdkGC *new_gc;
>        GdkGCValues style_values;
> 
>        style_gc = GTK_WIDGET(c)->style;
>        gdk_gc_get_values (style->fg_gc[state], &style_values);
>        new_gc = gdk_gc_new_with_values (GTK_WIDGET(c)->window,
>                                         &style_values, ~0);		
>        
>  
> This will segfault, because gdk_gc_new_with_values() checks the value
> mask for GDK_GC_TILE, which is set, and then proceeds to indirect into
> style_values.tile regardless of whether or not style_values.tile is set.
> 
> Granted, the ~0 should really be replaced by an OR of all possible
> enums, but this won't rid of the bug. 
> 
> I would enclose a patch, but I'm not sure how many similar cases like
> this exist. Its looks to me as though similar issues exist for
> clip_mask and stipple.

Well...

Note that X has no concept of setting the tile or stipple
to none; if you have a tile set, the only way to not use
it is to set the fill mode to something else.

So there is no real sane handling of NULL in these fields.

I suppose it could remove them from the mask if they are 
NULL, but that is at best a workaround.

It might be better to use gdk_gc_copy() in such a 
circumstance...

Regards,
                                        Owen



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]