]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
Use ARRAY_SIZE macro everywhere
authorPhil Sutter <phil@nwl.cc>
Tue, 28 Jun 2016 16:42:15 +0000 (18:42 +0200)
committerStephen Hemminger <shemming@brocade.com>
Wed, 29 Jun 2016 16:18:18 +0000 (09:18 -0700)
This patch was generated by the following semantic patch (a trimmed down
version of what is shipped with Linux sources):

@@
type T;
T[] E;
@@
(
- (sizeof(E)/sizeof(*E))
+ ARRAY_SIZE(E)
|
- (sizeof(E)/sizeof(E[...]))
+ ARRAY_SIZE(E)
|
- (sizeof(E)/sizeof(T))
+ ARRAY_SIZE(E)
)

The only manual adjustment was to include utils.h in misc/nstat.c to make
the macro known there.

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

index 353e1c3da45db791978378ea1c42adf4e5862d5f..b347040ccf91de08473c2418162e6d778d06c8a9 100644 (file)
@@ -319,7 +319,7 @@ static int brlink_modify(int argc, char **argv)
                } else if (strcmp(*argv, "state") == 0) {
                        NEXT_ARG();
                        char *endptr;
-                       size_t nstates = sizeof(port_states) / sizeof(*port_states);
+                       size_t nstates = ARRAY_SIZE(port_states);
 
                        state = strtol(*argv, &endptr, 10);
                        if (!(**argv != '\0' && *endptr == '\0')) {
index a9e0f20789e3c15036ca45b7f7315c2876a9c2a3..e579ce1d315862ff8dec1d8a44b0314db9e1feb3 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <json_writer.h>
 #include <SNAPSHOT.h>
+#include "utils.h"
 
 int dump_zeros;
 int reset_history;
@@ -95,7 +96,7 @@ static int useless_number(const char *id)
 {
        int i;
 
-       for (i = 0; i < sizeof(useless_numbers)/sizeof(*useless_numbers); i++)
+       for (i = 0; i < ARRAY_SIZE(useless_numbers); i++)
                if (strcmp(id, useless_numbers[i]) == 0)
                        return 1;
        return 0;
index 20ea3a44ffc5d8f45fa226d71c60a9ac2c6b6073..a0f9c6b9623c357ee69a1ddcfb6ddbd09c3311db 100644 (file)
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -666,7 +666,7 @@ static int get_slabstat(struct slabstat *s)
        while (fgets(buf, sizeof(buf), fp) != NULL) {
                int i;
 
-               for (i = 0; i < sizeof(slabstat_ids)/sizeof(slabstat_ids[0]); i++) {
+               for (i = 0; i < ARRAY_SIZE(slabstat_ids); i++) {
                        if (memcmp(buf, slabstat_ids[i], strlen(slabstat_ids[i])) == 0) {
                                sscanf(buf, "%*s%d", ((int *)s) + i);
                                cnt--;