bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: paying for the sin of no unit tests: useless-if-before-free bug


From: Bruno Haible
Subject: Re: paying for the sin of no unit tests: useless-if-before-free bug
Date: Thu, 1 May 2008 17:48:54 +0200
User-agent: KMail/1.5.4

Jim Meyering wrote:
> Actually this seems more appropriately run from a checked-out
> gnulib directory, e.g., as part of a "make check" rule.

I would much prefer if the gnulib/Makefile "check" rule be reserved
to platform independent checks on the gnulib code. Tests of some programs
belong in the test module of that program, IMO, so that
  - the test is also performed when we test a gnulib testdir on various
    platforms,
  - gnulib/Makefile doesn't become a random collection of things, like
    the "system.h" a few years ago.

> u = ./useless-if-before-free
> SHELL = /bin/bash
> 
> all:
>       $u <(printf 'if (p) free(p);') > /dev/null
>       $u <(printf 'if (p) free((void)p);') > /dev/null
>       $u <(printf 'if (p) free( (void)p);') > /dev/null
>       $u <(printf 'if (p) free((T *) p);') > /dev/null
>       $u <(printf 'if (*p) free(*p);') > /dev/null
>       $u <(printf 'if (p)\nfree(p);') > /dev/null
>       $u <(printf 'if ( p ) free(p);') > /dev/null
>       $u <(printf 'if (p) free( p );') > /dev/null
>       $u <(printf 'if(p) free (p);') > /dev/null
>       $u <(printf 'if(p){free (p);}') > /dev/null
>       $u <(printf 'if(p){\nfree (p);}') > /dev/null
>       $u --name=z <(printf 'if (p) z (p);') > /dev/null
>       $u --name=z <(printf 'if(p)z(p);') > /dev/null
>       test $$($u --name=z <(printf 'if(p)z(p);if(p)z(p);')|wc -l) = 2

This is not too hard to put into the common shape of gnulib tests:

  TESTS_ENVIRONMENT += auxdir='$(top_srcdir)/build-aux/'

[note: 'build-aux' here is correct, it this is automatically replaced
with the value of $ac_aux_dir by gnulib-tool]
and in the test-*.sh file:

  echo 'if (p) free(p);' | $auxdir/useless-if-before-free > /dev/null || exit 1
  ...
  test `echo 'if(p)z(p);if(p)z(p);' | $auxdir/useless-if-before-free --name=z | 
wc -l` = 2 || exit 1

Btw, the useless-if-before-free help says that

Exit status:

  0   no match
  1   one or more matches

but it appears to be the opposite: 0 for one or more matches (like 'grep').

Bruno





reply via email to

[Prev in Thread] Current Thread [Next in Thread]