bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-grep] Non-constant array initializer in dfa.c


From: Paul Eggert
Subject: Re: [bug-grep] Non-constant array initializer in dfa.c
Date: Fri, 11 Mar 2005 14:21:59 -0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

Andreas Schwab <address@hidden> writes:

> Borzenkov Andrey <address@hidden> writes:
>>                         char expr[6] = { '[', c, '-', c2, ']', '\0' };
>
> The compiler is broken.  This is a perfectly valid initializer in C89.

No, because c and c2 are not constants.  In C89, initializers for
aggregates are required to be constants, even if you're initializing
an auto array (as is the case here).

This portability bug got fixed a while ago (see the enclosed patch to
dfa.c dated 2003) but the bug got reintroduced when the gawk version
was merged in December 2004.

--- dfa.c       4 Jun 2003 07:57:37 -0000       1.21
+++ dfa.c       8 Jul 2003 14:58:05 -0000       1.22
@@ -1053,12 +1053,15 @@ lex (void)
                          setbit_case_fold (c, ccl);
                      } else {
                        /* POSIX locales are painful - leave the decision to 
libc */
-                       char expr[6] = { '[', c, '-', c2, ']', '\0' };
+                       char expr[6] = { '[', 0 /* c */, '-', 0 /* c2 */, ']', 
'\0' };
                        regex_t re;
+                       expr[1] = c;
+                       expr[3] = c2;
                        if (regcomp (&re, expr, case_fold ? REG_ICASE : 0) == 
REG_NOERROR) {
                          for (c = 0; c < NOTCHAR; ++c) {
-                           char buf[2] = { c, '\0' };
+                           char buf[2] = { 0 /* c */, '\0' };
                            regmatch_t mat;
+                           buf[0] = c;
                            if (regexec (&re, buf, 1, &mat, 0) == REG_NOERROR
                                && mat.rm_so == 0 && mat.rm_eo == 1)
                               setbit_case_fold (c, ccl);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]