Makefile: add -Wno-stringop-truncation for y.tab.o
authorJens Axboe <axboe@kernel.dk>
Wed, 25 Jan 2023 03:54:48 +0000 (20:54 -0700)
committerJens Axboe <axboe@kernel.dk>
Wed, 25 Jan 2023 04:07:37 +0000 (21:07 -0700)
This file is auto-generated, and it currently spews the following
warning for me:

In function ‘setup_to_parse_string’,
    inlined from ‘evaluate_arithmetic_expression’ at y.tab.c:1571:2:
y.tab.c:1559:9: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-truncation]
 1559 |         strncpy(lexer_input_buffer, string, len);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
y.tab.c:1556:19: note: length computed here
 1556 |         if (len > strlen(string))
      |                   ^~~~~~~~~~~~~~

when compiled with:

gcc (Debian 12.2.0-14) 12.2.0

Just set -Wno-stringop-truncation unconditionally in the Makefile for
this file, don't think there's any point in checking if this warning
has been enabled manually.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Makefile
configure

index 9fd8f59b85e40e5b3480ff51372bd1465e32ea65..5f4e65620f5b027d7c4a9708d70b89c936455a88 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -554,11 +554,15 @@ ifneq (,$(findstring -Wimplicit-fallthrough,$(CFLAGS)))
 LEX_YY_CFLAGS := -Wno-implicit-fallthrough
 endif
 
+ifdef CONFIG_HAVE_NO_STRINGOP
+YTAB_YY_CFLAGS := -Wno-stringop-truncation
+endif
+
 lex.yy.o: lex.yy.c y.tab.h
        $(QUIET_CC)$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $(LEX_YY_CFLAGS) -c $<
 
 y.tab.o: y.tab.c y.tab.h
-       $(QUIET_CC)$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) -c $<
+       $(QUIET_CC)$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $(YTAB_YY_CFLAGS) -c $<
 
 y.tab.c: exp/expression-parser.y
        $(QUIET_YACC)$(YACC) -o $@ -l -d -b y $<
index 6d8e3a8712558ae8c4ecbacb974788457125cf78..a17d1cda1091e0419fbd0e2bec757604d2ae5929 100755 (executable)
--- a/configure
+++ b/configure
@@ -2826,6 +2826,22 @@ if compile_prog "-Wimplicit-fallthrough=2" "" "-Wimplicit-fallthrough=2"; then
 fi
 print_config "-Wimplicit-fallthrough=2" "$fallthrough"
 
+##########################################
+# check if the compiler has -Wno-stringop-concatenation
+no_stringop="no"
+cat > $TMPC << EOF
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+       return printf("%s\n", argv[0]);
+}
+EOF
+if compile_prog "-Wno-stringop-truncation -Werror" "" "no_stringop"; then
+  no_stringop="yes"
+fi
+print_config "-Wno-stringop-truncation" "$no_stringop"
+
 ##########################################
 # check for MADV_HUGEPAGE support
 if test "$thp" != "yes" ; then
@@ -3271,6 +3287,9 @@ fi
 if test "$fallthrough" = "yes"; then
   CFLAGS="$CFLAGS -Wimplicit-fallthrough"
 fi
+if test "$no_stringop" = "yes"; then
+  output_sym "CONFIG_HAVE_NO_STRINGOP"
+fi
 if test "$thp" = "yes" ; then
   output_sym "CONFIG_HAVE_THP"
 fi