[Olsr-dev] First batch of Coverity fixes

Bernd Petrovitsch (spam-protected)
Fri Jul 12 15:49:47 CEST 2013


Hi!

On Fre, 2013-07-12 at 14:04 +0200, Henning Rogge wrote:
[....]
> I would like to hear your opinions on this patchset:
[...]
> diff --git a/src/olsr_cookie.c b/src/olsr_cookie.c
> index dfd618a..feff0ae 100644
> --- a/src/olsr_cookie.c
> +++ b/src/olsr_cookie.c
> @@ -67,7 +67,12 @@ olsr_alloc_cookie(const char *cookie_name, 
> olsr_cookie_type cookie_type)
>       }
>     }
> 
> -  assert(ci_index < COOKIE_ID_MAX);     /* increase COOKIE_ID_MAX */
> +  if (ci_index == COOKIE_ID_MAX) {
> +    assert(false);     /* increase COOKIE_ID_MAX */

The output given by this "assert()" is probably more misleading than the
one from the original
	assert(ci_index < COOKIE_ID_MAX);
.
> +
> +    /* assert will not be there when compiled without debug information */

Yup, that is forgotten often. One needs a "stronger" assert() for that -
something like

#define ASSERT_EXIT(cond) do { assert(cond); if (!(cond)) exit(1); } while(0)

Side-effects on "cond" are evil anyways as it may be compiled out
completely ....

> +    exit(1);
> +  }

	Bernd
-- 
Bernd Petrovitsch                  Email : (spam-protected)
                     LUGA : http://www.luga.at





More information about the Olsr-dev mailing list