]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
iw: add and fix -Wsign-compare
authorJohannes Berg <johannes.berg@intel.com>
Wed, 14 Oct 2015 06:49:14 +0000 (08:49 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 14 Oct 2015 06:50:34 +0000 (08:50 +0200)
Ola Olsson pointed out that -Wsign-compare was getting a lot
of warnings, those seem reasonable to fix.

Reported-by: Ola Olsson <ola1olsson@gmail.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Makefile
bitrate.c
event.c
ibss.c
info.c
mesh.c
ocb.c
phy.c
util.c
vendor.c

index 548591a30a9fe8ff00a5eb7b756c02f7d83a1e99..e61825ecc766b2db8ec064770c4d5662aca3542c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,8 @@ INSTALL ?= install
 CC ?= "gcc"
 
 CFLAGS ?= -O2 -g
-CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration
+CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common \
+         -Werror-implicit-function-declaration -Wsign-compare
 
 OBJS = iw.o genl.o event.o info.o phy.o \
        interface.o ibss.o station.o survey.o util.o ocb.o \
index 87288583f3387c81ba102d91518c5bb2c1ca7847..4a026a48e1ba8b2ef26b98a4c257d7e9a284e5a4 100644 (file)
--- a/bitrate.c
+++ b/bitrate.c
@@ -6,7 +6,7 @@
 
 static int parse_vht_chunk(const char *arg, __u8 *nss, __u16 *mcs)
 {
-       int count, i;
+       unsigned int count, i;
        unsigned int inss, mcs_start, mcs_end, tab[10];
 
        *nss = 0; *mcs = 0;
diff --git a/event.c b/event.c
index a342dc46bcc9d2574ed46bb58ad5d9d81d2262e6..896f03ab7636a49b3e477581fa3744175437e27c 100644 (file)
--- a/event.c
+++ b/event.c
@@ -45,7 +45,7 @@ static void print_frame(struct print_event_args *args, struct nlattr *attr)
 {
        uint8_t *frame;
        size_t len;
-       int i;
+       unsigned int i;
        char macbuf[6*3];
        uint16_t tmp;
 
diff --git a/ibss.c b/ibss.c
index 23bda70bd655fe9618ebe62bb91abe6f31df91e7..024981af7af1a853041de5a9f2578f3972d798ba 100644 (file)
--- a/ibss.c
+++ b/ibss.c
@@ -25,8 +25,8 @@ struct chanmode {
 
 static int get_cf1(const struct chanmode *chanmode, unsigned long freq)
 {
-       int cf1 = freq, j;
-       int vht80[] = { 5180, 5260, 5500, 5580, 5660, 5745 };
+       unsigned int cf1 = freq, j;
+       unsigned int vht80[] = { 5180, 5260, 5500, 5580, 5660, 5745 };
 
        switch (chanmode->width) {
        case NL80211_CHAN_WIDTH_80:
@@ -61,7 +61,7 @@ static int join_ibss(struct nl80211_state *state,
        char *value = NULL, *sptr = NULL;
        float rate;
        int bintval;
-       int i;
+       unsigned int i;
        unsigned long freq;
        const struct chanmode *chanmode_selected = NULL;
        static const struct chanmode chanmode[] = {
diff --git a/info.c b/info.c
index 8e8739758632cf3137d442db57910cee29bda756..4ac1eabc14ba8be0052548e55a45ca25dde414b7 100644 (file)
--- a/info.c
+++ b/info.c
@@ -493,12 +493,13 @@ broken_combination:
                        if (tb_wowlan[NL80211_WOWLAN_TRIG_MAGIC_PKT])
                                printf("\t\t * wake up on magic packet\n");
                        if (tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
+                               unsigned int len = nla_len(tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN]);
+
                                pat = nla_data(tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN]);
                                printf("\t\t * wake up on pattern match, up to %u patterns of %u-%u bytes,\n"
                                        "\t\t   maximum packet offset %u bytes\n",
                                        pat->max_patterns, pat->min_pattern_len, pat->max_pattern_len,
-                                       (nla_len(tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN]) <
-                                       sizeof(*pat)) ? 0 : pat->max_pkt_offset);
+                                       len < sizeof(*pat) ? 0 : pat->max_pkt_offset);
                        }
                        if (tb_wowlan[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
                                printf("\t\t * can do GTK rekeying\n");
@@ -526,8 +527,10 @@ broken_combination:
 
        if (tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]) {
                struct ieee80211_ht_cap *cm;
+               unsigned int len = nla_len(tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]);
+
                printf("\tHT Capability overrides:\n");
-               if (nla_len(tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]) >= sizeof(*cm)) {
+               if (len >= sizeof(*cm)) {
                        cm = nla_data(tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]);
                        printf("\t\t * MCS: %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx"
                               " %02hhx %02hhx %02hhx %02hhx\n",
diff --git a/mesh.c b/mesh.c
index 290b8c2d186bc02a0be70958e47d094ff5325f72..460d0c99523d58177ccf2b099d2d5dc183f27a3f 100644 (file)
--- a/mesh.c
+++ b/mesh.c
@@ -268,7 +268,7 @@ const static struct mesh_param_descr _mesh_param_descrs[] =
 
 static void print_all_mesh_param_descr(void)
 {
-       int i;
+       unsigned int i;
 
        printf("Possible mesh parameters are:\n");
 
@@ -278,7 +278,7 @@ static void print_all_mesh_param_descr(void)
 
 static const struct mesh_param_descr *find_mesh_param(const char *name)
 {
-       int i;
+       unsigned int i;
 
        /* Find out what mesh parameter we want to change. */
        for (i = 0; i < ARRAY_SIZE(_mesh_param_descrs); i++) {
@@ -387,7 +387,7 @@ static int print_mesh_param_handler(struct nl_msg *msg, void *arg)
                return -EINVAL;
 
        if (!mdescr) {
-               int i;
+               unsigned int i;
 
                for (i = 0; i < ARRAY_SIZE(_mesh_param_descrs); i++) {
                        mdescr = &_mesh_param_descrs[i];
@@ -435,8 +435,9 @@ static int join_mesh(struct nl80211_state *state,
        struct nlattr *container;
        float rate;
        unsigned char rates[NL80211_MAX_SUPP_RATES];
-       int bintval, dtim_period, i, n_rates = 0;
+       int bintval, dtim_period, n_rates = 0;
        char *end, *value = NULL, *sptr = NULL;
+       unsigned int i;
        unsigned long freq = 0;
        static const struct {
                const char *name;
diff --git a/ocb.c b/ocb.c
index 1a380d53909f8def13aa1efd47d856db608d67f3..767eb82c51aef054cc870effed777e7270af0522 100644 (file)
--- a/ocb.c
+++ b/ocb.c
@@ -12,7 +12,7 @@ static int join_ocb(struct nl80211_state *state,
 {
        unsigned long freq;
        char *end;
-       int i;
+       unsigned int i;
        static const struct {
                const char *name;
                unsigned int width;
diff --git a/phy.c b/phy.c
index 6d4139ed7d7c5522cd68c40b33c0c17535b338ac..13e8260ed78a9f4519dbd9833ef970735c0e896a 100644 (file)
--- a/phy.c
+++ b/phy.c
@@ -44,7 +44,7 @@ static int handle_freqs(struct nl_msg *msg, int argc, char **argv)
                { .name = "160", .val = NL80211_CHAN_WIDTH_160, },
        };
        uint32_t freq;
-       int i, bwval = NL80211_CHAN_WIDTH_20_NOHT;
+       unsigned int i, bwval = NL80211_CHAN_WIDTH_20_NOHT;
        char *end;
 
        if (argc < 1)
@@ -103,7 +103,7 @@ static int handle_freqchan(struct nl_msg *msg, bool chan,
        };
        unsigned int htval = NL80211_CHAN_NO_HT;
        unsigned int freq;
-       int i;
+       unsigned int i;
 
        if (!argc || argc > 4)
                return 1;
diff --git a/util.c b/util.c
index 0bae9ef4f95995d59ada82c98a821955bacb97d5..55e1e26366edc83dfd1f8e28350a17e20843601b 100644 (file)
--- a/util.c
+++ b/util.c
@@ -716,7 +716,7 @@ void print_vht_info(__u32 capa, const __u8 *mcs)
 
 void iw_hexdump(const char *prefix, const __u8 *buf, size_t size)
 {
-       int i;
+       size_t i;
 
        printf("%s: ", prefix);
        for (i = 0; i < size; i++) {
index 86c03d1c5f63a09180be405d5e0f2be4eac1556f..279aac50727d941c5c0afe14aff4792c49604d7a 100644 (file)
--- a/vendor.c
+++ b/vendor.c
@@ -14,7 +14,8 @@ SECTION(vendor);
 
 static int read_file(FILE *file, char *buf, size_t size)
 {
-       int data, count = 0;
+       size_t count = 0;
+       int data;
 
        while ((data = fgetc(file)) != EOF) {
                if (count >= size)
@@ -26,10 +27,10 @@ static int read_file(FILE *file, char *buf, size_t size)
        return count;
 }
 
-static int read_hex(int argc, char **argv, char *buf, size_t size)
+static int read_hex(unsigned int argc, char **argv, char *buf, size_t size)
 {
-       int i, res;
-       unsigned int data;
+       unsigned int i, data;
+       int res;
 
        if (argc > size)
                return -EINVAL;