Browse files

array: return_if_fail() if element size is 0

This is particular useful for:
  g_array_new (sizeof (MyStruct), FALSE, FALSE);
because the correct incantation is
  g_array_new (FALSE, FALSE, sizeof (MyStruct));
and these warnings will trigger in the first situation.
  • Loading branch information...
1 parent 9d52243 commit a6e149e41f359c4bf2ddab341dad20e7fb2bd9f3 Benjamin Otte committed Jan 14, 2012
Showing with 8 additions and 2 deletions.
  1. +8 −2 glib/garray.c
View
10 glib/garray.c
@@ -162,7 +162,9 @@ g_array_new (gboolean zero_terminated,
gboolean clear,
guint elt_size)
{
- return (GArray*) g_array_sized_new (zero_terminated, clear, elt_size, 0);
+ g_return_val_if_fail (elt_size > 0, NULL);
+
+ return g_array_sized_new (zero_terminated, clear, elt_size, 0);
}
/**
@@ -185,7 +187,11 @@ GArray* g_array_sized_new (gboolean zero_terminated,
guint elt_size,
guint reserved_size)
{
- GRealArray *array = g_slice_new (GRealArray);
+ GRealArray *array;
+
+ g_return_val_if_fail (elt_size > 0, NULL);
+
+ array = g_slice_new (GRealArray);
array->data = NULL;
array->len = 0;

0 comments on commit a6e149e

Please sign in to comment.