From b86399bbee3e37b36ef60df8743da17ecea8c5dc Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 28 Oct 2019 14:07:05 -0400 Subject: [PATCH] ctf: define yystrlen to strlen MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Building with -Wnull-dereference on cygwin gives: LEX lexer.c CC libctf_parser_la-lexer.lo CC libctf_parser_la-parser.lo parser.c: In function ‘yysyntax_error’: parser.c:2566:24: error: potential null pointer dereference [-Werror=null-dereference] for (yylen = 0; yystr[yylen]; yylen++) ~~~~~^~~~~~~ For some reason, the conditional used by bison to define yystrlen makes it so that cygwin uses the bison-provided version instead of strlen: # ifndef yystrlen # if defined __GLIBC__ && defined _STRING_H # define yystrlen strlen # else /* Return the length of YYSTR. */ static YYSIZE_T yystrlen (const char *yystr) { YYSIZE_T yylen; for (yylen = 0; yystr[yylen]; yylen++) continue; return yylen; } # endif # endif Actually, probably because cygwin's string.h uses _STRING_H_ instead of _STRING_H as its include guard. As far as I know, strlen on cygwin (and on all the platforms we target) is reliable. So we can bypass this by defining yystrlen to strlen directly. Change-Id: I08a5d99a164e4e4f2cf44236be0ece94e16e7c57 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/2276 Reviewed-by: Francis Deslauriers --- src/plugins/ctf/common/metadata/parser.y | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/plugins/ctf/common/metadata/parser.y b/src/plugins/ctf/common/metadata/parser.y index 16868179..71f2d5fe 100644 --- a/src/plugins/ctf/common/metadata/parser.y +++ b/src/plugins/ctf/common/metadata/parser.y @@ -1036,6 +1036,17 @@ void ctf_scanner_free(struct ctf_scanner *scanner) free(scanner); } +/* + * The bison-provided version of strlen (yystrlen) generates a benign + * -Wnull-dereference warning. That version is used when building on cygwin, + * for example, but you can also enable it by hand (to test) by removing the + * preprocessor conditional around it. + * + * Define yystrlen such that it will always use strlen. As far as we know, + * strlen provided by all the platforms we use is reliable. + */ +#define yystrlen strlen + %} /* -- 2.34.1