[PATCH] tests: Don't increment variables inside an assert()

Bryce Harrington bryce at osg.samsung.com
Fri Jul 10 01:05:23 PDT 2015


On Fri, Jun 19, 2015 at 04:13:11PM -0700, Jon A. Cruz wrote:
> On 06/19/2015 03:58 PM, Bryce Harrington wrote:
> > Addresses this warning found by Denis Denisov:
> > 
> >   [tests/array-test.c:137]: (warning) Assert statement modifies 'i'.
> > 
> > Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
> > ---
> >  tests/array-test.c | 9 ++++++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> > 
> > diff --git a/tests/array-test.c b/tests/array-test.c
> > index 37b9afd..fe53240 100644
> > --- a/tests/array-test.c
> > +++ b/tests/array-test.c
> > @@ -126,7 +126,8 @@ TEST(array_for_each)
> >  {
> >  	static const int elements[] = { 77, 12, 45192, 53280, 334455 };
> >  	struct wl_array array;
> > -	int *p, i;
> > +	int *p;
> > +	int i;
> >  
> >  	wl_array_init(&array);
> >  	for (i = 0; i < 5; i++) {
> > @@ -136,8 +137,10 @@ TEST(array_for_each)
> >  	}
> >  
> >  	i = 0;
> > -	wl_array_for_each(p, &array)
> > -		assert(*p == elements[i++]);
> > +	wl_array_for_each(p, &array) {
> > +		assert(*p == elements[i]);
> > +		i++;
> > +	}
> >  	assert(i == 5);
> >  
> >  	wl_array_release(&array);
> 
> 
> The tests currently state they require DEBUG to be enabled in order to
> work, it is still very good to avoid modification from assert() wrapped
> code. Moving to a different framework could fail immediately due to this.
> 
> Looks good.
> 
> Reviewed-by: Jon A. Cruz <jonc at osg.samsung.com>

Thanks, pushed as commit c2547c70a739d74f02979a8b590018ad6cb440d8


More information about the wayland-devel mailing list