[Git][NTPsec/ntpsec][master] 5 commits: Fixes warnings from clang 1.7.

Hal Murray (@hal.murray) gitlab at mg.gitlab.com
Mon Feb 17 08:32:19 UTC 2025



Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
e7b622bf by Fred Wright at 2025-02-17T08:28:54+00:00
Fixes warnings from clang 1.7.

This fixes one case of format-string type mismatch with clang 1.7.  Since
the change simply coerces the type to the expected (and actual) value,
it should be reasonably safe.

TESTED:
Still builds without warnings on OSX 10.9 & 10.12, and Ubuntu 14.04.
Now builds without warnings on OSX 10.6.
No new warnings on OSX 10.5.

- - - - -
e6b1f412 by Fred Wright at 2025-02-17T08:28:54+00:00
ntp_io: Fix warning from some old compilers.

Some compilers (e.g. GCC 4.2) give a "shadowed global" warning due to
'new_interface' being both a function and a local variable.  Newer
compilers probably avoid it by treating functions and variables as
different in the shadowing check.  Renaming the local variable fixes
the issue (as well as being a bit more informative, anyway).

TESTED:
Now builds without warnings.

- - - - -
33cd363e by Fred Wright at 2025-02-17T08:28:54+00:00
Fix warnings with old Bisons.

Some old Bison versions produce switch() clauses without expected
default entries, triggering a warning when -Wswitch-default is
enabled.  And at least one generates references to undefined macros,
triggering warnings with -Wundef.

This change separates out the parser build and disables those warnings
on just that one compile, while leaving the other compiles alone.

The related top-level wscript comment is updated to reflect this.

TESTED:
Built and ran tests on OSX 10.4-10.5 ppc, 10.4-10.6 i386, 10.5-12.x
x86_64, 11.x-15.x arm64, Debian 7 arm, Debian 10 arm64, Ubuntu 14
x86_64, CentOS 7 x86_64, Fedora 25 x86_64, Ubuntu 22 x86_64, FreeBSD
10.3 x86_64, OpenBSD 5.6 x86_64, and OpenBSD i386.

- - - - -
9248106c by Fred Wright at 2025-02-17T08:28:54+00:00
Fix warnings on OpenBSD and FreeBSD.

On OpenBSD, the _XOPEN_SOURCE value must be at least 500 to get
strptime().  On FreeBSD, the value must be at least 700 to get
ldexpl(), which isn't directly used here but is referenced in
an included header.

TESTED:
Built and ran tests on OSX 10.4-10.5 ppc, 10.4-10.6 i386, 10.5-12.x
x86_64, 11.x-15.x arm64, Debian 7 arm, Debian 10 arm64, Ubuntu 14
x86_64, CentOS 7 x86_64, Fedora 25 x86_64, Ubuntu 22 x86_64, FreeBSD
10.3 x86_64, OpenBSD 5.6 x86_64, and OpenBSD i386.

- - - - -
f84500c8 by Fred Wright at 2025-02-17T08:28:54+00:00
ntp_packetstamp: Fix warning with old clang.

Really old clang versions (before 3.x) don't recognize the
unneeded-internal-declaration warning, and hence complain about the
pragma to disable it.  This fixes the condition for applying it.

TESTED:
Built and ran tests on OSX 10.4-10.5 ppc, 10.4-10.6 i386, 10.5-12.x
x86_64, 11.x-15.x arm64, Debian 7 arm, Debian 10 arm64, Ubuntu 14
x86_64, CentOS 7 x86_64, Fedora 25 x86_64, Ubuntu 22 x86_64, FreeBSD
10.3 x86_64, OpenBSD 5.6 x86_64, and OpenBSD i386.

- - - - -


6 changed files:

- libntp/socktoa.c
- libparse/clk_sel240x.c
- ntpd/ntp_io.c
- ntpd/ntp_packetstamp.c
- ntpd/wscript
- wscript


Changes:

=====================================
libntp/socktoa.c
=====================================
@@ -98,7 +98,7 @@ sockporttoa_r(
 		 (IS_IPV6(sock))
 		     ? "[%s]:%hu"
 		     : "%s:%hu",
-		 buf2, SRCPORT(sock));
+		 buf2, (unsigned short)SRCPORT(sock));
 	errno = saved_errno;
 
 	return buf;


=====================================
libparse/clk_sel240x.c
=====================================
@@ -5,7 +5,9 @@
 #include "config.h"
 
 // _XOPEN_SOURCE needed for strptime()
-#define _XOPEN_SOURCE
+// For OpenBSD, the value must be at least 500
+// For FreeBSD, the value must be at least 700 for ldexpl() in ntp_fp.h
+#define _XOPEN_SOURCE 700
 
 #include "ntp.h"	// only for the u_* typedefs from GCC; remove someday
 #include "ntp_syslog.h"


=====================================
ntpd/ntp_io.c
=====================================
@@ -1381,16 +1381,16 @@ is_valid(
 static bool
 update_interfaces(void)
 {
-  bool new_interface = false;
+  bool have_new_interface = false;
   update_interfaces_phase0();
   if (extra_port)
     /* do first so our requests are sent from extra_port
      * see select_peerinterface() */
-    new_interface |= update_interfaces_phase1(extra_port);
-  new_interface |= update_interfaces_phase1(NTP_PORT);
+    have_new_interface |= update_interfaces_phase1(extra_port);
+  have_new_interface |= update_interfaces_phase1(NTP_PORT);
   update_interfaces_phase2();
   update_interfaces_phase3();
-  return new_interface;
+  return have_new_interface;
 }
 
 void update_interfaces_phase0(void)


=====================================
ntpd/ntp_packetstamp.c
=====================================
@@ -116,7 +116,7 @@ static const union {
 #define MAX_TV_USEC 1000000
 #define MAX_TV_NSEC 1000000000
 
-#if defined (__clang__)
+#if defined (__clang_major__) && __clang_major__ >= 3
 #pragma clang diagnostic ignored "-Wunneeded-internal-declaration"
 #endif
 


=====================================
ntpd/wscript
=====================================
@@ -80,6 +80,20 @@ def build(ctx):
         # use="libntpd_obj bison_obj",
     )
 
+    # Build the parser separately, so that we can disable -Wswitch-default
+    # on this one build, since old Bisons run afoul of it.  Also, at least
+    # one old Bison generates a couple of references to undefined macros,
+    # so we disable that warning as well.
+    ctx(
+        target="parser_obj",
+        features="c",
+        source=ctx.bldnode.parent.find_node("host/ntpd/ntp_parser.tab.c"),
+        includes=[
+            ctx.bldnode.parent.abspath(), "../include",
+            "%s/host/ntpd/" % ctx.bldnode.parent.abspath(), "." ],
+        cflags=["-Wno-switch-default", "-Wno-undef"],  # For old Bisons
+    )
+
     use_refclock = ""      # XXX: there must be a better way to do this
     if ctx.env.REFCLOCK_ENABLE:
 
@@ -120,7 +134,6 @@ def build(ctx):
         "ntp_timer.c",
         "ntp_dns.c",
         "ntpd.c",
-        ctx.bldnode.parent.find_node("host/ntpd/ntp_parser.tab.c")
     ]
 
     ctx(
@@ -131,7 +144,7 @@ def build(ctx):
         install_path='${SBINDIR}',
         source=ntpd_source,
         target="ntpd",
-        use="libntpd_obj ntp M parse RT CAP SECCOMP PTHREAD NTPD "
+        use="libntpd_obj parser_obj ntp M parse RT CAP SECCOMP PTHREAD NTPD "
             "CRYPTO SSL DNS_SD %s SOCKET NSL SCF" % use_refclock,
     )
 


=====================================
wscript
=====================================
@@ -361,7 +361,8 @@ def configure(ctx):
             # "-Wpadded",             # duck... over 3k warnings
             # "-Wredundant-decls",    # incompatible w/ Unity
             "-Wswitch-default",       # warns on missing switch-default
-                                        # old Bison triggers this
+                                        # suppressed on parser build
+                                        # to avoid trouble with old Bisons
             "-Wswitch-enum",          # warns on missing enum case handler
         ] + ctx.env.CFLAGS
         cc_test_flags += [



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/dd386e7de3f4a02e9dd3a4e96381a590f36f376a...f84500c8d8d517ee50145be527a751fd4175ba02

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/dd386e7de3f4a02e9dd3a4e96381a590f36f376a...f84500c8d8d517ee50145be527a751fd4175ba02
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20250217/dd7d7cd8/attachment-0001.htm>


More information about the vc mailing list