This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Undefined behavior in genautomata.c?


On Mon, Sep 19, 2005 at 11:14:20AM +0200, Sebastian Pop wrote:
> +   /* decls is statically declared as containing a single element, but
> +      then, during the execution, other data is appended to the end of
> +      this array, and elements over the statically allocated size are
> +      accessed!  This undefined behavior could affect a lot of
> +      programs, now that VRP is doing its work.  The problem is that
> +      these cases are difficult to detect and diagnose without a
> +      warning.
> + 
> +      The fix is to declare this array as dynamically allocated as:
> + 
> +      decl_t *decls;
> + 
> +      then dynamically allocate its elements.  */
>     decl_t decls [1];

Oh, and I'll have to say that this idiom is *so* common in C90
code, predating the specific C99 syntax, that you simply cannot
add code that breaks it.  At least not enabled by default.


r~


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]