[Git][NTPsec/ntpsec][master] Use PRI* macros in printf format strings for uint64_t to avoid warnings

Matt Selsky gitlab at mg.gitlab.com
Sun Dec 17 11:09:58 UTC 2017


Matt Selsky pushed to branch master at NTPsec / ntpsec


Commits:
eec12943 by Matt Selsky at 2017-12-17T05:54:18-05:00
Use PRI* macros in printf format strings for uint64_t to avoid warnings

Example:
../../ntpd/ntp_util.c:596:39: warning: format specifies type 'unsigned long' but the argument has type 'uint64_t' (aka 'unsigned long long') [-Wformat]
                    sys_oldversion, sys_restricted, sys_badlength,
                                                    ^~~~~~~~~~~~~

- - - - -


2 changed files:

- ntpd/ntp_control.c
- ntpd/ntp_util.c


Changes:

=====================================
ntpd/ntp_control.c
=====================================
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -10,6 +10,7 @@
 #include <sys/stat.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <inttypes.h>
 
 #include <openssl/evp.h>	/* provides OpenSSL digest API */
 
@@ -1200,11 +1201,7 @@ ctl_putuint(
 
 	*cp++ = '=';
 	INSIST((cp - buffer) < (int)sizeof(buffer));
-#if (NTP_SIZEOF_LONG == 8)
-	snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer), "%lu", uval);
-#else
-	snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer), "%llu", uval);
-#endif
+	snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer), "%" PRIu64, uval);
 	cp += strlen(cp);
 	ctl_putdata(buffer, (unsigned)( cp - buffer ), false);
 }
@@ -1263,11 +1260,7 @@ ctl_puthex(
 
 	*cp++ = '=';
 	INSIST((cp - buffer) < (int)sizeof(buffer));
-#if (NTP_SIZEOF_LONG == 8)
-	snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer), "0x%lx", uval);
-#else
-	snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer), "0x%llx", uval);
-#endif
+	snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer), "0x%" PRIx64, uval);
 	cp += strlen(cp);
 	ctl_putdata(buffer,(unsigned)( cp - buffer ), false);
 }


=====================================
ntpd/ntp_util.c
=====================================
--- a/ntpd/ntp_util.c
+++ b/ntpd/ntp_util.c
@@ -20,6 +20,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include <sys/stat.h>
+#include <inttypes.h>
 
 #ifdef HAVE_GETRUSAGE
 #include <sys/time.h>
@@ -585,11 +586,8 @@ record_sys_stats(void)
 	filegen_setup(&sysstats, now.tv_sec);
 	if (sysstats.fp != NULL) {
 		fprintf(sysstats.fp,
-#if (NTP_SIZEOF_LONG == 8)
-		    "%s %u %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
-#else
-		    "%s %u %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
-#endif
+		    "%s %u %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64
+		    " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 "\n",
 		    timespec_to_MJDtime(&now), current_time - sys_stattime,
 		    sys_received, sys_processed, sys_newversion,
 		    sys_oldversion, sys_restricted, sys_badlength,



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/eec12943bc1d17f6ef55d8d2ce3a3b7403bc832c

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/eec12943bc1d17f6ef55d8d2ce3a3b7403bc832c
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/20171217/238a2133/attachment.html>


More information about the vc mailing list