From 8ad824b7e1f4f2fc952de23861f2182af3de8b76 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 7 Oct 2021 15:21:02 -0700 Subject: [PATCH] netconsd: Fix printing of uint64_t's in modules Summary: Building on arm64 currently warns with ``` logger.cc: In function 'void write_log(logtarget&, msg_buf*, ncrx_msg*)': logger.cc:121:19: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'uint64_t' {aka 'long long unsigned int'} [-Wformat=] dprintf(tgt.fd, "%06lu %014lu %d %d %s%s%s%s%s\n", msg->seq, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~ logger.cc:121:19: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'uint64_t' {aka 'long long unsigned int'} [-Wformat=] g++ logger.o -lpthread -lrt -ldl -shared -static-libstdc++ -static-libgcc \ -o logger.so ``` It also segfaults as soon as it gets an extended message, due to the %lu trying to read 8 bytes, while the argument is just 4. Use a portable type to make the build dtrt on x86-64 and arm64 Reviewed By: davide125 Differential Revision: D30970654 fbshipit-source-id: 6edc47d48486e2f66644bbec6405024d8e948cad --- modules/logger.cc | 6 ++++-- modules/printer.c | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/logger.cc b/modules/logger.cc index 53bdc57..4089667 100644 --- a/modules/logger.cc +++ b/modules/logger.cc @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -118,8 +119,9 @@ static void write_log(struct logtarget& tgt, struct msg_buf *buf, if (!msg) dprintf(tgt.fd, "%s\n", buf->buf); else - dprintf(tgt.fd, "%06lu %014lu %d %d %s%s%s%s%s\n", msg->seq, - msg->ts_usec, msg->facility, msg->level, + dprintf(tgt.fd, "%06" PRIu64 " %014" PRIu64 " %d %d %s%s%s%s%s\n", + msg->seq, msg->ts_usec, + msg->facility, msg->level, msg->cont_start ? "[CONT START] " : "", msg->cont ? "[CONT] " : "", msg->oos ? "[OOS] ": "", diff --git a/modules/printer.c b/modules/printer.c index 5f7a57c..894da56 100644 --- a/modules/printer.c +++ b/modules/printer.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -37,7 +38,7 @@ void netconsd_output_handler(int t, struct in6_addr *src, struct msg_buf *buf, if (!msg) printf("%40s: %s\n", addr, buf->buf); else - printf("%40s: S%06lu T%014lu F%d/L%d %s%s%s%s%s\n", addr, + printf("%40s: S%06" PRIu64 " T%014" PRIu64 " F%d/L%d %s%s%s%s%s\n", addr, msg->seq, msg->ts_usec, msg->facility, msg->level, msg->cont_start ? "[CONT START] " : "", msg->cont ? "[CONT] " : "",