[PATCH] netstat.c: sscanf portability fix and size reduction
Rich Felker
dalias at aerifal.cx
Fri May 19 06:39:47 UTC 2006
range expressions are unspecified for *scanf. using %[^:] instead of
%[0-9A-Fa-f] saves a few bytes and fixes the problem. the data comes
from the kernel so there should be no issue with accepting extra
unwanted characters here.
rich
-------------- next part --------------
Index: networking/netstat.c
===================================================================
--- networking/netstat.c (revision 15108)
+++ networking/netstat.c (working copy)
@@ -170,7 +170,7 @@
more[0] = '\0';
num = sscanf(line,
- "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s\n",
+ "%d: %64[^:]:%X %64[^:]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s\n",
&d, local_addr, &local_port,
rem_addr, &rem_port, &state,
&txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more);
@@ -240,7 +240,7 @@
more[0] = '\0';
num = sscanf(line,
- "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s\n",
+ "%d: %64[^:]:%X %64[^:]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s\n",
&d, local_addr, &local_port,
rem_addr, &rem_port, &state,
&txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more);
@@ -335,7 +335,7 @@
more[0] = '\0';
num = sscanf(line,
- "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s\n",
+ "%d: %64[^:]:%X %64[^:]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s\n",
&d, local_addr, &local_port,
rem_addr, &rem_port, &state,
&txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more);
More information about the busybox
mailing list