[Git][NTPsec/ntpsec][master] 3 commits: ntp_control.c: Fix a compiler warning

Hal Murray (@hal.murray) gitlab at mg.gitlab.com
Thu Dec 21 16:33:27 UTC 2023



Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
60a2ad14 by Fred Wright at 2023-12-21T00:27:15-08:00
ntp_control.c: Fix a compiler warning

The expression was shifting a char left before promoting it to
a short.  This should actually be OK, since intermediate results
are supposed to be int or better, but it's more conceptually correct
to promote it first, which avoids a warning from GCC 4.2.  It's
also slightly better to do the mask before the shift.

TESTED:
Now builds without warnings and passes tests, with 28 compilers
from GCC 4.2 and Clang 3.3 to GCC 13 and Clang 17.

- - - - -
bb663654 by Fred Wright at 2023-12-21T00:37:21-08:00
Fix some timespec initializer warnings

Some compilers don't seem to recognize that clock_gettime() storing
into a struct timespec counts as initializing it, and produce "may be
used uninitialized" warnings.  Adding initializers to the structs gets
rid of the warnings, without adding enough overhead to worry about.

TESTED:
Now builds without warnings and passes tests, with 28 compilers
from GCC 4.2 and Clang 3.3 to GCC 13 and Clang 17.

- - - - -
0fdfe692 by Fred Wright at 2023-12-21T00:56:09-08:00
aes_siv: Remove troublesome -Wconversion

This warning is known to be overzealous in GCC 4.2, and apparently
toned down in later GCC versions.

According to devel/CommitLog-4.1.0, it was removed from the "classic"
CFLAGS in 2001-04-21, and hadn't resurfaced until it was applied
here solely to aes_siv components in 468fc5a7c9.

TESTED:
Now builds without warnings and passes tests, with 28 compilers
from GCC 4.2 and Clang 3.3 to GCC 13 and Clang 17.

- - - - -


6 changed files:

- libaes_siv/wscript
- ntpd/ntp_control.c
- ntpd/refclock_nmea.c
- ntpfrob/bumpclock.c
- ntpfrob/jitter.c
- ntpfrob/precision.c


Changes:

=====================================
libaes_siv/wscript
=====================================
@@ -1,7 +1,7 @@
 def build(ctx):
     aes_cflags=['-Wno-shadow',
             # '-Wall', '-Wextra', '-Wstrict-prototypes',  # default
-            '-Wconversion',
+            # '-Wconversion',  # Overzealous in GCC 4.2
             '-O3',
             '-fomit-frame-pointer',
             '-funroll-loops',


=====================================
ntpd/ntp_control.c
=====================================
@@ -762,7 +762,7 @@ ctl_error(
 	 */
 	rpkt.r_m_e_op = (uint8_t)CTL_RESPONSE | CTL_ERROR |
 			(res_opcode & CTL_OP_MASK);
-	rpkt.status = htons((unsigned short)(errcode << 8) & 0xff00);
+	rpkt.status = htons((unsigned short)(errcode & 0xff) << 8);
 	rpkt.count = 0;
 
 	/*


=====================================
ntpd/refclock_nmea.c
=====================================
@@ -1668,7 +1668,7 @@ parse_date(
  *
  */
 static bool kludge_day (struct timespec *dt) {
-  struct timespec now;
+  struct timespec now = {0, 0};
 
   clock_gettime(CLOCK_REALTIME, &now);
   int nowday = now.tv_sec / 86400;


=====================================
ntpfrob/bumpclock.c
=====================================
@@ -19,7 +19,7 @@
 
 void bumpclock(int64_t bump)
 {
-    struct timespec was, set, now;
+    struct timespec was = {0, 0}, now = {0, 0}, set;
     int rc1, rc2, rc3;
     int er1, er2, er3;
 


=====================================
ntpfrob/jitter.c
=====================================
@@ -38,7 +38,7 @@ get_clocktime(
 {
 	doubletime_t dtemp;
 
-	struct timespec ts;	/* seconds and nanoseconds */
+	struct timespec ts = {0, 0};	/* seconds and nanoseconds */
 
 	/*
 	 * Convert Unix clock from seconds and nanoseconds to seconds.


=====================================
ntpfrob/precision.c
=====================================
@@ -70,7 +70,7 @@ void precision(const iomode mode)
 int
 default_get_resolution(void)
 {
-	struct timespec tp;
+	struct timespec tp = {0, 0};
 	long last;
 	int i;
 	long diff;
@@ -132,7 +132,7 @@ default_get_resolution(void)
 int
 default_get_precision(void)
 {
-	struct timespec tp;
+	struct timespec tp = {0, 0};
 	long last;
 	int i;
 	long diff;



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/86636d8d5c7a1cac87a77dd9b0d808b09174e698...0fdfe69295d96ae7e94648faa8fedb6f4c8ec1b3

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/86636d8d5c7a1cac87a77dd9b0d808b09174e698...0fdfe69295d96ae7e94648faa8fedb6f4c8ec1b3
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/20231221/81335b2f/attachment-0001.htm>


More information about the vc mailing list