This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Undefined behavior in genautomata.c?
- From: Richard Henderson <rth at redhat dot com>
- To: Sebastian Pop <sebastian dot pop at cri dot ensmp dot fr>
- Cc: gcc at gcc dot gnu dot org, Vladimir Makarov <vmakarov at redhat dot com>
- Date: Mon, 19 Sep 2005 02:20:42 -0700
- Subject: Re: Undefined behavior in genautomata.c?
- References: <20050919091420.GA5325@napoca.cri.ensmp.fr>
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~