Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit a6e149e41f359c4bf2ddab341dad20e7fb2bd9f3 1 parent 9d52243
Benjamin Otte authored

Showing 1 changed file with 8 additions and 2 deletions. Show diff stats Hide diff stats

  1. +8 2 glib/garray.c
10 glib/garray.c
@@ -162,7 +162,9 @@ g_array_new (gboolean zero_terminated,
162 162 gboolean clear,
163 163 guint elt_size)
164 164 {
165   - return (GArray*) g_array_sized_new (zero_terminated, clear, elt_size, 0);
  165 + g_return_val_if_fail (elt_size > 0, NULL);
  166 +
  167 + return g_array_sized_new (zero_terminated, clear, elt_size, 0);
166 168 }
167 169
168 170 /**
@@ -185,7 +187,11 @@ GArray* g_array_sized_new (gboolean zero_terminated,
185 187 guint elt_size,
186 188 guint reserved_size)
187 189 {
188   - GRealArray *array = g_slice_new (GRealArray);
  190 + GRealArray *array;
  191 +
  192 + g_return_val_if_fail (elt_size > 0, NULL);
  193 +
  194 + array = g_slice_new (GRealArray);
189 195
190 196 array->data = NULL;
191 197 array->len = 0;

0 comments on commit a6e149e

Please sign in to comment.
Something went wrong with that request. Please try again.