Re: asr(4) error with new clang/llvm

From: David Chisnall <theraven_at_FreeBSD.org>
Date: Fri, 2 Jan 2015 09:07:13 +0000
On 2 Jan 2015, at 05:00, Ed Maste <emaste_at_freebsd.org> wrote:
> 
> It's a variable length array in a struct / union. Other than being
> confusing and now triggering a warning after the clang update it
> should be fine.
> 
> Most likely we need to build asr with -Werror disabled for that
> warning, perhaps -Wno-error-array-bounds. I'll take a look tomorrow
> morning if nobody else gets to it first.

The correct solution is to declare the array to have 0 elements (although this will break C++ code).  A zero-length array at the end of a structure is specifically defined by the C standard (since C99) to be a variable-length array.  A length-one array was used in C89 prior to this for this purpose.  Using a 1-element array in C is undefined behaviour.

Note that this change will also require fixing code that allocates it to allocate space for n elements not n-1.

David
Received on Fri Jan 02 2015 - 08:07:23 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:54 UTC