From 7aa9f970e88382f2508ee55122e27cdcfd8cdbda Mon Sep 17 00:00:00 2001 From: James McCoy Date: Thu, 1 May 2014 11:14:31 -0400 Subject: all: Use macros for printf/scanf format specifiers Any types that are fixed width should use the standard format specifier macros (PRI... for printf-type functions, SCN... for scanf-type functions) to ensure proper data access. Prior to this ifpps was crashing in 32-bit environments due to the following call mvwprintw(screen, (*voff)++, 2, "%s,%s %s (%s%s), t=%lums, cpus=%u%s/%u" " ", uts.release, machine, ifname, drvinf.driver, buff, ms_interval, top_cpus, top_cpus > 0 && top_cpus < cpus ? "+1" : "", cpus); since ms_interval is a uint64_t but %lu expects an unsigned long, which is only 32 bits. Signed-off-by: James McCoy Signed-off-by: Tobias Klauser --- flowtop.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'flowtop.c') diff --git a/flowtop.c b/flowtop.c index 5b0a88c..5a283f7 100644 --- a/flowtop.c +++ b/flowtop.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "die.h" #include "xmalloc.h" @@ -751,7 +752,7 @@ static void presenter_screen_do_line(WINDOW *screen, struct flow_entry *n, /* PID, application name */ if (n->procnum > 0) { - slprintf(tmp, sizeof(tmp), "%s(%u)", basename(n->cmdline), + slprintf(tmp, sizeof(tmp), "%s(%d)", basename(n->cmdline), n->procnum); printw("["); @@ -806,7 +807,7 @@ static void presenter_screen_do_line(WINDOW *screen, struct flow_entry *n, /* Number packets, bytes */ if (n->counter_pkts > 0 && n->counter_bytes > 0) - printw(" (%llu pkts, %llu bytes) ->", + printw(" (%"PRIu64" pkts, %"PRIu64" bytes) ->", n->counter_pkts, n->counter_bytes); /* Show source information: reverse DNS, port, country, city */ @@ -815,7 +816,7 @@ static void presenter_screen_do_line(WINDOW *screen, struct flow_entry *n, mvwprintw(screen, ++(*line), 8, "src: %s", n->rev_dns_src); attroff(COLOR_PAIR(1)); - printw(":%u", n->port_src); + printw(":%"PRIu16, n->port_src); if (n->country_src[0]) { printw(" ("); @@ -838,7 +839,7 @@ static void presenter_screen_do_line(WINDOW *screen, struct flow_entry *n, mvwprintw(screen, ++(*line), 8, "dst: %s", n->rev_dns_dst); attroff(COLOR_PAIR(2)); - printw(":%u", n->port_dst); + printw(":%"PRIu16, n->port_dst); if (n->country_dst[0]) { printw(" ("); -- cgit v1.2.3-54-g00ecf