Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Wed, 26 Oct 2011 11:24:43 +0400
From: Solar Designer <solar@...nwall.com>
To: john-dev@...ts.openwall.com
Subject: Re: clang warning

On Wed, Oct 26, 2011 at 01:20:36AM +0200, magnum wrote:
> Clang emits this warning. Is it a false alarm? This code is from 2002.
> 
> single.c:330:8: warning: array index of '1' indexes past the end of an
> array (that contains 1 elements) [-Warray-bounds]
>                         if (first->data[1]) {
>                             ^           ~
> In file included from single.c:15:
> In file included from ./loader.h:16:
> ./list.h:19:7: note: array 'data' declared here
>         char data[1];
>              ^
> 1 warning generated.

Yes, a false alarm, and the code is from 1998 as far as I recall (but
that was prior to import into CVS).

I guess it is more common to use zero-sized arrays for this (and maybe
clang won't issue a warning then), but they're less portable.  So I am
not sure how to fix this best.

An obvious fix would be to use "char *data" and allocate it separately,
but this is essentially undoing an optimization - it would waste memory.

Thanks for reporting!

Alexander

Powered by blists - more mailing lists

Your e-mail address:

Powered by Openwall GNU/*/Linux - Powered by OpenVZ