Glib array 'bug'?



Hi All,

I have found something in the array implementation in glib 1.0.4 that I would 
consider a bug. At least a very inconvenient feature. :) A quick look at the 
1.0.5 sources shows the same thing.

When constructing a resizable array with g_array_new( TRUE ), which implies 
that the array will be NULL-terminated (i.e. an extra element with value NULL 
is always kept at the end), the array->data is still NULL. Looking at garray.c, 
it seems that it will account for this terminating NULL element when resizing 
the array, but not when allocating it.

A workaround is to say something like this in your code:

  array = g_array_new( TRUE );
  null = NULL;
  g_array_append_val( array, GrIPort *, null );
  g_array_truncate( array, GrIPort *, 0 );

But this seems to be a slight pain in the, erm, programmer's behind.

Now, I know that there has been an overhaul of the array code in the 1.1 
branch, where this may have been fixed (or not?), but perhaps it should be 
fixed in the 1.0 branch anyway?

Regards,

Johannes.
--
"FLASH!  Intelligence of mankind decreasing.  Details at ... uh, when
 the little hand is on the ...." -- Jarek Luberek

Visually inspecting visual programming languages.




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