[Git][NTPsec/ntpsec][master] Fix printf of sa_family_t variables.

Eric S. Raymond gitlab at mg.gitlab.com
Wed Sep 28 20:25:29 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
a14dfc86 by Matt Selsky at 2016-09-28T16:02:31-04:00
Fix printf of sa_family_t variables.

sa_family_t is different sizes on different platforms (eg unsigned char on osx;
unsigned short on linux).  For portability, cast to uintmax_t, since we're
guaranteed to avoid loss of precision, and then use the format specifier for
that type.

- - - - -


1 changed file:

- tests/common/sockaddrtest.c


Changes:

=====================================
tests/common/sockaddrtest.c
=====================================
--- a/tests/common/sockaddrtest.c
+++ b/tests/common/sockaddrtest.c
@@ -1,13 +1,16 @@
 #ifndef GUARD_TESTS_SOCKADDRTEST_H
 #define GUARD_TESTS_SOCKADDRTEST_H
 
+#include <inttypes.h>
+
 #include "config.h"
 
 #include "ntp.h"
 
 bool IsEqualS(const sockaddr_u *expected, const sockaddr_u *actual) {
 	if (expected->sa.sa_family != actual->sa.sa_family) {
-		printf("Expected sa_family: %hhu but got: %hhu\n", expected->sa.sa_family, actual->sa.sa_family);
+		printf("Expected sa_family: %" PRIuMAX " but got: %" PRIuMAX "\n",
+		       (uintmax_t)expected->sa.sa_family, (uintmax_t)actual->sa.sa_family);
 		return false;
 	}
 
@@ -30,7 +33,7 @@ bool IsEqualS(const sockaddr_u *expected, const sockaddr_u *actual) {
 			return false;
 		}
 	} else { // Unknown family
-		printf("Unknown sa_family: %hhu\n", actual->sa.sa_family);
+		printf("Unknown sa_family: %" PRIuMAX "\n", (uintmax_t)actual->sa.sa_family);
 		return false;
 	}
 }



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/a14dfc86a3c465afc57c9139099ecd0a1f03e6a9
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160928/b5bf27da/attachment.html>


More information about the vc mailing list