Undefined behavior in genautomata.c?
Richard Henderson
rth@redhat.com
Mon Sep 19 09:20:00 GMT 2005
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~
More information about the Gcc
mailing list