{"thread":{"id":"42546","subject":"[PATCH v2] regex: fix a SIZE_MAX macro redefinition warning","startedAt":"2016-06-07T00:35:33Z","lastAt":"2016-06-07T00:35:33Z","messageCount":1,"participants":["Ramsay Jones"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"288501","messageId":"575616D5.8000008@ramsayjones.plus.com","threadId":"42546","inReplyTo":null,"subject":"[PATCH v2] regex: fix a SIZE_MAX macro redefinition warning","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2016-06-07T00:35:33Z","receivedAt":"2016-06-07T00:35:33Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\nSince commit 56a1a3ab (\"Silence GCC's \\\"cast of pointer to integer of a\ndifferent size\\\" warning\", 26-10-2015), sparse has been issuing a macro\nredefinition warning for the SIZE_MAX macro. However, gcc did not issue\nany such warning.\n\nAfter commit 56a1a3ab, in terms of the order of #includes and #defines,\nthe code looked something like:\n\n  $ cat -n junk.c\n       1\t#include <stddef.h>\n       2\n       3\t#define SIZE_MAX ((size_t) -1)\n       4\n       5\t#include <stdint.h>\n       6\n       7\tint main(int argc, char *argv[])\n       8\t{\n       9\t\treturn 0;\n      10\t}\n  $\n  $ gcc junk.c\n  $\n\nHowever, if you compile that file with -Wsystem-headers, then it will\nalso issue a warning. Having set -Wsystem-headers in CFLAGS, using the\nconfig.mak file, then (on cygwin):\n\n  $ make compat/regex/regex.o\n      CC compat/regex/regex.o\n  In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/stdint.h:9:0,\n                   from compat/regex/regcomp.c:21,\n                   from compat/regex/regex.c:77:\n  /usr/include/stdint.h:362:0: warning: \"SIZE_MAX\" redefined\n   #define SIZE_MAX (__SIZE_MAX__)\n   ^\n  In file included from compat/regex/regex.c:69:0:\n  compat/regex/regex_internal.h:108:0: note: this is the location of the previous definition\n   # define SIZE_MAX ((size_t) -1)\n   ^\n  $\n\nThe compilation of the compat/regex code is somewhat unusual in that the\nregex.c file directly #includes the other c files (regcomp.c, regexec.c\nand regex_internal.c). Commit 56a1a3ab added an #include of <stdint.h>\nto the regcomp.c file, which results in the redefinition, since this is\nincluded after the regex_internal.h header. This header file contains a\n'fallback' definition for SIZE_MAX, in order to support systems which do\nnot have the <stdint.h> header (the HAVE_STDINT_H macro is not defined).\n\nIn order to suppress the warning, we move the #include of <stdint.h>\nfrom regcomp.c to the start of the compilation unit, close to the top\nof regex.c, prior to the #include of the regex_internal.h header.\n\nSigned-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n---\n\nChange from v1:\n\t- add the #include <stdint.h> to the top of regex.c, rather than\n\t  use HAVE_STDINT_H to 'activate' the conditional inclusion of\n\t  <stdint.h> in the regex_internal.h header.\n\nJunio and Johannes - thanks for the feedback on v1 of the patch.\n\nATB,\nRamsay Jones\n\n compat/regex/regcomp.c | 2 --\n compat/regex/regex.c   | 1 +\n 2 files changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/compat/regex/regcomp.c b/compat/regex/regcomp.c\nindex fba5986..d8bde06 100644\n--- a/compat/regex/regcomp.c\n+++ b/compat/regex/regcomp.c\n@@ -18,8 +18,6 @@\n    Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\n    02110-1301 USA.  */\n \n-#include <stdint.h>\n-\n static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern,\n \t\t\t\t\t  size_t length, reg_syntax_t syntax);\n static void re_compile_fastmap_iter (regex_t *bufp,\ndiff --git a/compat/regex/regex.c b/compat/regex/regex.c\nindex 6aaae00..5cb23e5 100644\n--- a/compat/regex/regex.c\n+++ b/compat/regex/regex.c\n@@ -60,6 +60,7 @@\n    GNU regex allows.  Include it before <regex.h>, which correctly\n    #undefs RE_DUP_MAX and sets it to the right value.  */\n #include <limits.h>\n+#include <stdint.h>\n \n #ifdef GAWK\n #undef alloca\n-- \n2.8.0\n"}]}