]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 3846] Use -Wno-format-truncation by default.
authorDave Hart <hart@ntp.org>
Fri, 14 Jul 2023 21:33:19 +0000 (21:33 +0000)
committerDave Hart <hart@ntp.org>
Fri, 14 Jul 2023 21:33:19 +0000 (21:33 +0000)
bk: 64b1bf1fHCJUW-Pue0adfQdNL_3JuQ

ChangeLog
sntp/m4/ntp_compiler.m4

index 93cdab8b94eb430d9e1cf091711f64b15317250a..0a91317de37785e3d364421251b0acbc0113d496 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+---
+* [Bug 3846] Use -Wno-format-truncation by default.
+
 ---
 (4.2.8p17) 2023/06/06 Released by Harlan Stenn <stenn@ntp.org>
 
index ddce106fe5229e8393dbff5856795a02c439957d..6f603b0879ee2863427e7db9a6a6c1bdef084a71 100644 (file)
@@ -9,8 +9,6 @@ AC_USE_SYSTEM_EXTENSIONS
 AM_PROG_CC_C_O
 AC_PROG_GCC_TRADITIONAL
 AC_REQUIRE([AC_PROG_CC_STDC])
-dnl AC_REQUIRE([AC_PROG_CC_C89])
-dnl AC_REQUIRE([AC_PROG_CC_C99])
 
 CC_NOFORMAT=
 CFLAGS_NTP=
@@ -104,13 +102,16 @@ case "$GCC" in
        ]
     )
     #
+    # $ntp_cv_gcc_Winit_self is tested later to add the 
+    # flag to CFLAGS_NTP.
+    #
     # libopts specifically builds a string with embedded NULs.
     # This causes a bunch of distracting warnings due to -Wformat.
     # Let's see if we can figure out how to disable these.
     #
-    CFLAGS="$SAVED_CFLAGS -Wno-format"
+    CFLAGS="$SAVED_CFLAGS -Wno-format -Wno-format-security"
     AC_CACHE_CHECK(
-       [if $CC can handle -Wno-format], 
+       [if $CC can handle -Wno-format -Wno-format-security], 
        [ntp_cv_gcc_Wno_format],
        [
            AC_COMPILE_IFELSE(
@@ -122,33 +123,44 @@ case "$GCC" in
     )
 
     case "$ntp_cv_gcc_Wno_format" in
+      no) ntp_cv_gcc_Wno_format_truncation=no
+         ;;
      yes)
-       CC_NOFORMAT="$CC_NOFORMAT -Wno-format"
-       ;;
-     no)
-       ;;
+       CC_NOFORMAT="-Wno-format -Wno-format-security"
+       CFLAGS="$SAVED_CFLAGS -Wformat -Wno-format-truncation -Werror"
+       AC_CACHE_CHECK(
+               [if $CC can handle -Wformat -Wno-format-truncation], 
+               [ntp_cv_gcc_Wno_format_truncation], 
+               [AC_COMPILE_IFELSE(
+                   [AC_LANG_PROGRAM([[]], [[]])],
+                   [ntp_cv_gcc_Wno_format_truncation=yes],
+                   [ntp_cv_gcc_Wno_format_truncation=no]
+               )       ]
+       )
+       #
+       # $ntp_cv_gcc_Wno_format_truncation is tested later to add the 
+       # flag to CFLAGS.
+       #
     esac
 
+
     CFLAGS="$SAVED_CFLAGS"
     AS_UNSET([SAVED_CFLAGS])
-    #
-    # $ntp_cv_gcc_Winit_self is tested later to add the 
-    # flag to CFLAGS_NTP.
-    #
+
     AC_CACHE_CHECK(
        [if linker supports omitting unused code and data],
        [ntp_cv_gc_sections_runs],
        [
-           dnl  NetBSD will link but likely not run with --gc-sections
-           dnl  http://bugs.ntp.org/1844
-           dnl  http://gnats.netbsd.org/40401
-           dnl  --gc-sections causes attempt to load as linux elf, with
-           dnl  wrong syscalls in place.  Test a little gauntlet of
-           dnl  simple stdio read code checking for errors, expecting
-           dnl  enough syscall differences that the NetBSD code will
-           dnl  fail even with Linux emulation working as designed.
-           dnl  A shorter test could be refined by someone with access
-           dnl  to a NetBSD host with Linux emulation working.
+           #  NetBSD will link but likely not run with --gc-sections
+           #  http://bugs.ntp.org/1844
+           #  http://gnats.netbsd.org/40401
+           #  --gc-sections causes attempt to load as linux elf, with
+           #  wrong syscalls in place.  Test a little gauntlet of
+           #  simple stdio read code checking for errors, expecting
+           #  enough syscall differences that the NetBSD code will
+           #  fail even with Linux emulation working as designed.
+           #  A shorter test could be refined by someone with access
+           #  to a NetBSD host with Linux emulation working.
            origCFLAGS="$CFLAGS"
            CFLAGS="$CFLAGS -Wl,--gc-sections"
            AC_LINK_IFELSE(
@@ -223,6 +235,10 @@ case "$GCC" in
      yes)
        CFLAGS_NTP="$CFLAGS_NTP -Wstrict-overflow"
     esac
+    case "$ntp_cv_gcc_Wno_format_truncation" in
+     yes)
+       CFLAGS_NTP="$CFLAGS_NTP -Wno-format-truncation"
+    esac
     # -W[no-]strict-prototypes might be added by NTP_OPENSSL
 esac