Skip to content

Commit

Permalink
pppd: Fix printing 64-bit counters (#528)
Browse files Browse the repository at this point in the history
Add support of format specifiers %lld and %llu to the function vslprintf
and use the correct specifiers for printing 64-bit counters.

Signed-off-by: Tomas Paukrt <[email protected]>
  • Loading branch information
tpaukrt authored Oct 29, 2024
1 parent 346125f commit f7120b5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pppd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ print_link_stats(void)
if (link_stats_print && link_stats_valid) {
int t = (link_connect_time + 5) / 6; /* 1/10ths of minutes */
info("Connect time %d.%d minutes.", t/10, t%10);
info("Sent %u bytes, received %u bytes.",
info("Sent %llu bytes, received %llu bytes.",
link_stats.bytes_out, link_stats.bytes_in);
link_stats_print = 0;
}
Expand Down
28 changes: 26 additions & 2 deletions pppd/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ vslprintf(char *buf, int buflen, const char *fmt, va_list args)
int c, i, n;
int width, prec, fillch;
int base, len, neg, quoted;
long lval = 0;
unsigned long val = 0;
long long lval = 0;
unsigned long long val = 0;
char *str, *buf0;
const char *f;
unsigned char *p;
Expand Down Expand Up @@ -208,6 +208,30 @@ vslprintf(char *buf, int buflen, const char *fmt, va_list args)
case 'l':
c = *fmt++;
switch (c) {
case 'l':
c = *fmt++;
switch (c) {
case 'd':
lval = va_arg(args, long long);
if (lval < 0) {
neg = 1;
val = -lval;
} else
val = lval;
base = 10;
break;
case 'u':
val = va_arg(args, unsigned long long);
base = 10;
break;
default:
OUTCHAR('%');
OUTCHAR('l');
OUTCHAR('l');
--fmt; /* so %llz outputs %llz etc. */
continue;
}
break;
case 'd':
lval = va_arg(args, long);
if (lval < 0) {
Expand Down

0 comments on commit f7120b5

Please sign in to comment.