Commit a6e149e4 authored by Benjamin Otte's avatar Benjamin Otte

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.
parent 9d522437
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment