Fix more wrong sizeof() usages, part 1/x
authorSascha Wildner <saw@online.de>
Sat, 16 Jun 2012 10:31:23 +0000 (12:31 +0200)
committerSascha Wildner <saw@online.de>
Sat, 16 Jun 2012 11:22:18 +0000 (13:22 +0200)
These cases should all be taking the size of the pointed to struct etc.,
instead of the pointer size.

Found-with: Coccinelle (http://coccinelle.lip6.fr/)

lib/libatm/ip_addr.c
libexec/dma/spool.c
sys/dev/netif/iwl/iwl2100.c
sys/kern/kern_exit.c
sys/kern/subr_firmware.c
sys/net/sppp/if_spppsubr.c
sys/vfs/hammer/hammer_volume.c
tools/tools/net80211/wesside/dics/dics.c

index e252db6..2400b2c 100644 (file)
@@ -142,7 +142,7 @@ format_ip_addr(struct in_addr *addr)
        /*
         * Look up name in DNS
         */
-       ip_host = gethostbyaddr(addr, sizeof(addr), AF_INET);
+       ip_host = gethostbyaddr(addr, sizeof(*addr), AF_INET);
        if (ip_host && ip_host->h_name &&
                        strlen(ip_host->h_name)) {
                /*
index 25c6a99..9c4d79e 100644 (file)
@@ -284,7 +284,7 @@ load_queue(struct queue *queue)
        char *queuefn;
        char *mailfn;
 
-       bzero(queue, sizeof(queue));
+       bzero(queue, sizeof(*queue));
        LIST_INIT(&queue->queue);
 
        spooldir = opendir(config.spooldir);
index 51e0378..85f0716 100644 (file)
@@ -1948,7 +1948,7 @@ iwl2100_set_opmode(struct iwl2100_softc *sc, enum ieee80211_opmode opmode)
        }
 
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
 
        cmd->c_cmd = IWL2100_CMD_SET_OPMODE;
        cmd->c_param_len = sizeof(cmd->c_param[0]);
@@ -1989,7 +1989,7 @@ iwl2100_set_80211(struct iwl2100_softc *sc)
        }
 
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
 
        cmd->c_cmd = IWL2100_CMD_SET_80211;
        cmd->c_param_len = sizeof(cmd->c_param[0]) * 3;
@@ -2022,7 +2022,7 @@ iwl2100_set_basicrates(struct iwl2100_softc *sc)
        }
 
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
 
        /*
         * This configuration does not seem to have any effects
@@ -2064,7 +2064,7 @@ iwl2100_set_txrates(struct iwl2100_softc *sc)
         * Set TX rates
         */
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
 
        cmd->c_cmd = IWL2100_CMD_SET_TXRATES;
        cmd->c_param_len = sizeof(cmd->c_param[0]);
@@ -2080,7 +2080,7 @@ iwl2100_set_txrates(struct iwl2100_softc *sc)
         * Set MSDU TX rates
         */
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
 
        cmd->c_cmd = IWL2100_CMD_SET_MSDU_TXRATES;
        cmd->c_param_len = sizeof(cmd->c_param[0]);
@@ -2106,7 +2106,7 @@ iwl2100_set_powersave(struct iwl2100_softc *sc, int on)
        }
 
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
 
        cmd->c_cmd = IWL2100_CMD_SET_POWERSAVE;
        cmd->c_param_len = sizeof(cmd->c_param[0]);
@@ -2132,7 +2132,7 @@ iwl2100_set_rtsthreshold(struct iwl2100_softc *sc, uint16_t rtsthreshold)
        }
 
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
 
        cmd->c_cmd = IWL2100_CMD_SET_RTSTHRESHOLD;
        cmd->c_param_len = sizeof(cmd->c_param[0]);
@@ -2165,7 +2165,7 @@ iwl2100_set_bssid(struct iwl2100_softc *sc, const uint8_t *bssid)
        }
 
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
 
        cmd->c_cmd = IWL2100_CMD_SET_BSSID;
        if (bssid != NULL) {
@@ -2193,7 +2193,7 @@ iwl2100_set_essid(struct iwl2100_softc *sc, const uint8_t *essid, int essid_len)
        }
 
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
 
        cmd->c_cmd = IWL2100_CMD_SET_ESSID;
        if (essid != NULL) {
@@ -2225,7 +2225,7 @@ iwl2100_set_auth_ciphers(struct iwl2100_softc *sc,
        }
 
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
 
        cmd->c_cmd = IWL2100_CMD_SET_SECURITY;
        cmd->c_param_len = sizeof(*sec);
@@ -2265,7 +2265,7 @@ iwl2100_set_wepkey(struct iwl2100_softc *sc, const struct ieee80211_key *k)
        }
 
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
 
        cmd->c_cmd = IWL2100_CMD_SET_WEPKEY;
        cmd->c_param_len = sizeof(*key);
@@ -2294,7 +2294,7 @@ iwl2100_set_weptxkey(struct iwl2100_softc *sc, ieee80211_keyix txkey)
        }
 
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
 
        cmd->c_cmd = IWL2100_CMD_SET_WEPTXKEY;
        cmd->c_param_len = sizeof(cmd->c_param[0]);
@@ -2320,7 +2320,7 @@ iwl2100_set_privacy(struct iwl2100_softc *sc, int on)
        }
 
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
 
        cmd->c_cmd = IWL2100_CMD_SET_PRIVACY;
        cmd->c_param_len = sizeof(cmd->c_param[0]);
@@ -2682,7 +2682,7 @@ iwl2100_config_op(struct iwl2100_softc *sc, uint32_t op)
        }
 
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
        cmd->c_cmd = op;
 
        error = iwl2100_wait_cmd(sc);
@@ -2717,7 +2717,7 @@ iwl2100_set_chan(struct iwl2100_softc *sc, const struct ieee80211_channel *c)
        }
 
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
 
        cmd->c_cmd = IWL2100_CMD_SET_CHAN;
        cmd->c_param_len = sizeof(cmd->c_param[0]);
@@ -2746,7 +2746,7 @@ iwl2100_set_scanopt(struct iwl2100_softc *sc, uint32_t chans, uint32_t flags)
        }
 
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
 
        /*
         * NOTE:
@@ -2785,7 +2785,7 @@ iwl2100_set_scan(struct iwl2100_softc *sc)
        }
 
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
 
        cmd->c_cmd = IWL2100_CMD_SCAN;
        cmd->c_param_len = sizeof(cmd->c_param[0]);
@@ -2819,7 +2819,7 @@ iwl2100_set_optie(struct iwl2100_softc *sc, void *optie, uint16_t optie_len)
                return 0;
 
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
 
        cmd->c_cmd = IWL2100_CMD_SET_IE;
        cmd->c_param_len = sizeof(*ie);
@@ -2847,7 +2847,7 @@ iwl2100_set_bintval(struct iwl2100_softc *sc, uint16_t bintval)
        }
 
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
 
        cmd->c_cmd = IWL2100_CMD_SET_BINTVAL;
        cmd->c_param_len = sizeof(cmd->c_param[0]);
@@ -2873,7 +2873,7 @@ iwl2100_set_txpower(struct iwl2100_softc *sc, uint16_t txpower)
        }
 
        cmd = mtod(sc->sc_cmd, struct iwl2100_cmd *);
-       bzero(cmd, sizeof(cmd));
+       bzero(cmd, sizeof(*cmd));
 
        cmd->c_cmd = IWL2100_CMD_SET_TXPOWER;
        cmd->c_param_len = sizeof(cmd->c_param[0]);
index 93189e6..18123fd 100644 (file)
@@ -1004,7 +1004,7 @@ loop:
                                *status = W_STOPCODE(p->p_xstat);
                        /* Zero rusage so we get something consistent. */
                        if (rusage)
-                               bzero(rusage, sizeof(rusage));
+                               bzero(rusage, sizeof(*rusage));
                        error = 0;
                        lwkt_reltoken(&p->p_token);
                        goto done;
index bacb43c..483339d 100644 (file)
@@ -195,7 +195,7 @@ firmware_register(const char *imagename, const void *data, size_t datasize,
                    __func__, imagename);
                return NULL;
        }
-       bzero(frp, sizeof(frp));        /* start from a clean record */
+       bzero(frp, sizeof(*frp));       /* start from a clean record */
        frp->fw.name = imagename;
        frp->fw.data = data;
        frp->fw.datasize = datasize;
index 8af93dd..1b9bcd6 100644 (file)
@@ -3550,7 +3550,7 @@ sppp_ipv6cp_RCR(struct sppp *sp, struct lcp_header *h, int len)
                                continue;
                        }
 
-                       bzero(&suggestaddr, sizeof(&suggestaddr));
+                       bzero(&suggestaddr, sizeof(suggestaddr));
                        if (collision && nohisaddr) {
                                /* collision, hisaddr unknown - Conf-Rej */
                                type = CONF_REJ;
index 9f3cfd0..30a1a55 100644 (file)
@@ -577,7 +577,7 @@ format_callback(hammer_transaction_t trans, hammer_volume_t volume,
                KKASSERT(layer1->phys_offset == HAMMER_BLOCKMAP_UNAVAIL);
 
                hammer_modify_buffer(trans, *bufferp, layer1, sizeof(*layer1));
-               bzero(layer1, sizeof(layer1));
+               bzero(layer1, sizeof(*layer1));
                layer1->phys_offset = phys_off;
                layer1->blocks_free = stat->counter;
                layer1->layer1_crc = crc32(layer1, HAMMER_LAYER1_CRCSIZE);
@@ -669,7 +669,7 @@ free_callback(hammer_transaction_t trans, hammer_volume_t volume __unused,
                 * Free the L1 entry
                 */
                hammer_modify_buffer(trans, *bufferp, layer1, sizeof(*layer1));
-               bzero(layer1, sizeof(layer1));
+               bzero(layer1, sizeof(*layer1));
                layer1->phys_offset = HAMMER_BLOCKMAP_UNAVAIL;
                layer1->layer1_crc = crc32(layer1, HAMMER_LAYER1_CRCSIZE);
                hammer_modify_buffer_done(*bufferp);
index f03d993..e6edb55 100644 (file)
@@ -332,7 +332,7 @@ int main(int argc, char *argv[]) {
 
        sip = argv[1];
 
-       memset(&s_in, 0, sizeof(&s_in));
+       memset(&s_in, 0, sizeof(s_in));
        us = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP);
        if (s == -1) {
                perror("socket()");