diff options
author | Jiri Popelka <jpopelka@redhat.com> | 2012-06-21 15:51:05 +0200 |
---|---|---|
committer | Jiri Popelka <jpopelka@redhat.com> | 2012-06-26 12:05:28 +0200 |
commit | 53c401782cb84978cf99113833cf9651fb8a4d67 (patch) | |
tree | 394933c4fb98f98d5785de5dcb55e0eaef7383fb | |
parent | 699e5db88236deff1ff4cc657a8d978c25790587 (diff) | |
download | net-tools-53c401782cb84978cf99113833cf9651fb8a4d67.tar.gz net-tools-53c401782cb84978cf99113833cf9651fb8a4d67.tar.bz2 net-tools-53c401782cb84978cf99113833cf9651fb8a4d67.zip |
use scanf("%ms") instead of scanf("%as") for dynamic string
from scanf(3):
The a modifier is not available if the program is compiled with
gcc -std=c99 or gcc -D_ISOC99_SOURCE (unless _GNU_SOURCE
is also specified), in which case the a is interpreted
as a specifier for floating-point numbers (see above).
Since version 2.7, glibc also provides the m modifier for the
same purpose as the a modifier. The m modifier has the following
advantages:
* It may also be applied to %c conversion specifiers (e.g., %3mc).
* It avoids ambiguity with respect to the %a floating-point
conversion specifier (and is unaffected by gcc -std=c99 etc.)
* It is specified in the upcoming revision of the POSIX.1 standard.
-rw-r--r-- | lib/ddp_gr.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/ddp_gr.c b/lib/ddp_gr.c index c99dc0d..e08daa4 100644 --- a/lib/ddp_gr.c +++ b/lib/ddp_gr.c @@ -73,17 +73,17 @@ int DDP_rprint(int options) return 1; } - if (fscanf(fp, "%as %as %as %as\n", &dest, &gw, &flags, &dev)) + if (fscanf(fp, "%ms %ms %ms %ms\n", &dest, &gw, &flags, &dev)) /* eat line */; - free(dest); free(gw); free(dev); free(flags); + free(dest); free(gw); free(flags); free(dev); printf("%s\n", hdr); - while (fscanf(fp, "%as %as %as %as\n", &dest, &gw, &flags, &dev) == 4) { + while (fscanf(fp, "%ms %ms %ms %ms\n", &dest, &gw, &flags, &dev) == 4) { int iflags = atoi(flags); flags_decode(iflags, oflags); printf("%-16s%-16s%-16s%-s\n", dest, gw, dev, oflags); - free(dest); free(gw); free(dev); free(flags); + free(dest); free(gw); free(flags); free(dev); } fclose(fp); |