]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
get rid of unnecessary fgets() buffer size limitation
authorPhil Sutter <phil@nwl.cc>
Sat, 28 Nov 2015 00:00:05 +0000 (01:00 +0100)
committerStephen Hemminger <shemming@brocade.com>
Sun, 29 Nov 2015 19:48:24 +0000 (11:48 -0800)
fgets() will read at most size-1 bytes into the buffer and add a
terminating null-char at the end. Therefore it is not necessary to pass
a reduced buffer size when calling it.

This change was generated using the following semantic patch:

@@
identifier buf, fp;
@@
- fgets(buf, sizeof(buf) - 1, fp)
+ fgets(buf, sizeof(buf), fp)

Signed-off-by: Phil Sutter <phil@nwl.cc>
misc/arpd.c
misc/ss.c

index 7919eb8b36bb7659c4173a2bc0348684f1eee590..6bb9bd16bc46c5ff7b9416e16b06a6f740fb177a 100644 (file)
@@ -703,7 +703,7 @@ int main(int argc, char **argv)
                }
 
                buf[sizeof(buf)-1] = 0;
-               while (fgets(buf, sizeof(buf)-1, fp)) {
+               while (fgets(buf, sizeof(buf), fp)) {
                        __u8 b1[6];
                        char ipbuf[128];
                        char macbuf[128];
index d509009429de175fbc2f7ce02baa11496ad3abf0..0dab32ceff594ea2ecec53356f0fd1666400242d 100644 (file)
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -2729,7 +2729,7 @@ static int unix_show(struct filter *f)
 
        if ((fp = net_unix_open()) == NULL)
                return -1;
-       if (!fgets(buf, sizeof(buf)-1, fp)) {
+       if (!fgets(buf, sizeof(buf), fp)) {
                fclose(fp);
                return -1;
        }
@@ -2738,7 +2738,7 @@ static int unix_show(struct filter *f)
                newformat = 1;
        cnt = 0;
 
-       while (fgets(buf, sizeof(buf)-1, fp)) {
+       while (fgets(buf, sizeof(buf), fp)) {
                struct sockstat *u, **insp;
                int flags;
 
@@ -3217,12 +3217,12 @@ static int netlink_show(struct filter *f)
 
        if ((fp = net_netlink_open()) == NULL)
                return -1;
-       if (!fgets(buf, sizeof(buf)-1, fp)) {
+       if (!fgets(buf, sizeof(buf), fp)) {
                fclose(fp);
                return -1;
        }
 
-       while (fgets(buf, sizeof(buf)-1, fp)) {
+       while (fgets(buf, sizeof(buf), fp)) {
                sscanf(buf, "%llx %d %d %x %d %d %llx %d",
                       &sk,
                       &prot, &pid, &groups, &rq, &wq, &cb, &rc);