Skip to content

Commit bd8f005

Browse files
ramsay-jonesgitster
authored andcommitted
regex: fix a SIZE_MAX macro redefinition warning
Since commit 56a1a3a ("Silence GCC's \"cast of pointer to integer of a different size\" warning", 26-10-2015), sparse has been issuing a macro redefinition warning for the SIZE_MAX macro. However, gcc did not issue any such warning. After commit 56a1a3a, in terms of the order of #includes and #defines, the code looked something like: $ cat -n junk.c 1 #include <stddef.h> 2 3 #define SIZE_MAX ((size_t) -1) 4 5 #include <stdint.h> 6 7 int main(int argc, char *argv[]) 8 { 9 return 0; 10 } $ $ gcc junk.c $ However, if you compile that file with -Wsystem-headers, then it will also issue a warning. Having set -Wsystem-headers in CFLAGS, using the config.mak file, then (on cygwin): $ make compat/regex/regex.o CC compat/regex/regex.o In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/stdint.h:9:0, from compat/regex/regcomp.c:21, from compat/regex/regex.c:77: /usr/include/stdint.h:362:0: warning: "SIZE_MAX" redefined #define SIZE_MAX (__SIZE_MAX__) ^ In file included from compat/regex/regex.c:69:0: compat/regex/regex_internal.h:108:0: note: this is the location of the previous definition # define SIZE_MAX ((size_t) -1) ^ $ The compilation of the compat/regex code is somewhat unusual in that the regex.c file directly #includes the other c files (regcomp.c, regexec.c and regex_internal.c). Commit 56a1a3a added an #include of <stdint.h> to the regcomp.c file, which results in the redefinition, since this is included after the regex_internal.h header. This header file contains a 'fallback' definition for SIZE_MAX, in order to support systems which do not have the <stdint.h> header (the HAVE_STDINT_H macro is not defined). In order to suppress the warning, we move the #include of <stdint.h> from regcomp.c to the start of the compilation unit, close to the top of regex.c, prior to the #include of the regex_internal.h header. Signed-off-by: Ramsay Jones <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0b65a8d commit bd8f005

File tree

2 files changed

+1
-2
lines changed

2 files changed

+1
-2
lines changed

compat/regex/regcomp.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
1919
02110-1301 USA. */
2020

21-
#include <stdint.h>
22-
2321
static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern,
2422
size_t length, reg_syntax_t syntax);
2523
static void re_compile_fastmap_iter (regex_t *bufp,

compat/regex/regex.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
GNU regex allows. Include it before <regex.h>, which correctly
6161
#undefs RE_DUP_MAX and sets it to the right value. */
6262
#include <limits.h>
63+
#include <stdint.h>
6364

6465
#ifdef GAWK
6566
#undef alloca

0 commit comments

Comments
 (0)