|
Message-ID: <20120625084132.GA9406@openwall.com> Date: Mon, 25 Jun 2012 12:41:32 +0400 From: Solar Designer <solar@...nwall.com> To: john-dev@...ts.openwall.com Subject: Re: compiler warnings: make clean linux-x86-clang > /dev/null On Mon, Jun 25, 2012 at 10:26:22AM +0200, Frank Dittrich wrote: > But some definitely look suspicious: > > > 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]; > ^ This is as intended. "struct list_entry" is allocated dynamically, with just sufficient space to hold the actual "data". An alternative would have been to have extra pointer indirection here, which would waste a little bit of memory on the pointer and be a little bit slower. That said, I welcome suggestions on how to avoid scaring the compiler with what looks to it like an out-of-bounds access. A real concern is that some compiler might think that since the behavior is undefined anyway, it can optimize this out, or maybe trap it as a runtime fault. IIRC, formally we're only allowed to take the address of the array element just beyond the limit (e.g., &data[1] would be valid), but not dereference it. Alexander
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.