[PATCH] wayland util: Handle malloc failure in wl_array_copy()

Kristian Høgsberg hoegsberg at gmail.com
Mon Jul 23 08:11:08 PDT 2012


On Mon, Jul 23, 2012 at 11:40:52AM +0300, Pekka Paalanen wrote:
> On Sun, 22 Jul 2012 14:24:15 -0400
> Kristian Høgsberg <hoegsberg at gmail.com> wrote:
> 
> > > diff --git a/tests/array-test.c b/tests/array-test.c
> > > index 7639878..ff5bb8c 100644
> > > --- a/tests/array-test.c
> > > +++ b/tests/array-test.c
> > > @@ -60,7 +60,9 @@ TEST(array_add)
> > >  
> > >  	/* add some data */
> > >  	for (i = 0; i < iterations; i++) {
> > > -		struct mydata* ptr = wl_array_add(&array, datasize);
> > > +		struct mydata* ptr = NULL;
> > > +		while (ptr == NULL)
> > > +			ptr = wl_array_add(&array, datasize);
> > >  		assert((i + 1) * datasize == array.size);
> > 
> > If we want to test our malloc failure paths, we should inject malloc
> > errors using our malloc wrapper in test/test-runner.c, not by forcing
> > out-of-memory.  The typical approach here is to run the test once to
> > see how many mallocs there are, then run it once for each malloc,
> > failing malloc i in iteration i.
> 
> We don't have a realloc() wrapper yet, do we?
> Array uses realloc. We're missing calloc(), too, no?

Yea, we don't have those.

Kristian


More information about the wayland-devel mailing list