]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Convert os_zalloc() for an array to use os_calloc()
authorJouni Malinen <j@w1.fi>
Mon, 13 Aug 2012 17:44:21 +0000 (20:44 +0300)
committerJouni Malinen <j@w1.fi>
Mon, 13 Aug 2012 17:44:21 +0000 (20:44 +0300)
Signed-hostap: Jouni Malinen <j@w1.fi>

16 files changed:
hostapd/main.c
src/ap/hw_features.c
src/ap/ieee802_1x.c
src/drivers/driver_ndis.c
src/drivers/driver_nl80211.c
src/drivers/driver_privsep.c
src/drivers/driver_test.c
src/radius/radius.c
wlantest/wlantest_cli.c
wpa_supplicant/ap.c
wpa_supplicant/config.c
wpa_supplicant/dbus/dbus_new_handlers.c
wpa_supplicant/dbus/dbus_new_handlers_p2p.c
wpa_supplicant/interworking.c
wpa_supplicant/sme.c
wpa_supplicant/wpa_cli.c

index 3826ccf8303f3c5fa778e16ca455b82e3d9b99ef..35b4da9a4790afc46ccf59a53016a785f0984c9c 100644 (file)
@@ -181,7 +181,7 @@ static struct hostapd_iface * hostapd_init(const char *config_file)
        hapd_iface->conf = conf;
 
        hapd_iface->num_bss = conf->num_bss;
-       hapd_iface->bss = os_zalloc(conf->num_bss *
+       hapd_iface->bss = os_calloc(conf->num_bss,
                                    sizeof(struct hostapd_data *));
        if (hapd_iface->bss == NULL)
                goto fail;
@@ -254,7 +254,7 @@ static int hostapd_driver_init(struct hostapd_iface *iface)
        params.use_pae_group_addr = hapd->conf->use_pae_group_addr;
 
        params.num_bridge = hapd->iface->num_bss;
-       params.bridge = os_zalloc(hapd->iface->num_bss * sizeof(char *));
+       params.bridge = os_calloc(hapd->iface->num_bss, sizeof(char *));
        if (params.bridge == NULL)
                return -1;
        for (i = 0; i < hapd->iface->num_bss; i++) {
@@ -411,7 +411,7 @@ static int hostapd_global_init(struct hapd_interfaces *interfaces,
                wpa_printf(MSG_ERROR, "No drivers enabled");
                return -1;
        }
-       global.drv_priv = os_zalloc(global.drv_count * sizeof(void *));
+       global.drv_priv = os_calloc(global.drv_count, sizeof(void *));
        if (global.drv_priv == NULL)
                return -1;
 
@@ -592,7 +592,7 @@ int main(int argc, char *argv[])
                wpa_debug_open_file(log_file);
 
        interfaces.count = argc - optind;
-       interfaces.iface = os_zalloc(interfaces.count *
+       interfaces.iface = os_calloc(interfaces.count,
                                     sizeof(struct hostapd_iface *));
        if (interfaces.iface == NULL) {
                wpa_printf(MSG_ERROR, "malloc failed");
index 76c42118de5089600e33e0c436685c70dc1c72fc..76aff7750230a3e7d87598b6606f6bbae6524a34 100644 (file)
@@ -138,7 +138,7 @@ int hostapd_prepare_rates(struct hostapd_iface *iface,
        iface->num_rates = 0;
 
        iface->current_rates =
-               os_zalloc(mode->num_rates * sizeof(struct hostapd_rate_data));
+               os_calloc(mode->num_rates, sizeof(struct hostapd_rate_data));
        if (!iface->current_rates) {
                wpa_printf(MSG_ERROR, "Failed to allocate memory for rate "
                           "table.");
@@ -470,7 +470,7 @@ static void ieee80211n_scan_channels_2g4(struct hostapd_iface *iface,
                   affected_start, affected_end);
 
        mode = iface->current_mode;
-       params->freqs = os_zalloc((mode->num_channels + 1) * sizeof(int));
+       params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
        if (params->freqs == NULL)
                return;
        pos = 0;
index f76860ed4c3bd1bd44b5887e57dd6de5aa7c5087..d4c3e485e790f6e5d30eb17ef5f2fd9c9d6e6011 100644 (file)
@@ -1205,7 +1205,7 @@ static void ieee802_1x_store_radius_class(struct hostapd_data *hapd,
        if (count <= 0)
                return;
 
-       nclass = os_zalloc(count * sizeof(struct radius_attr_data));
+       nclass = os_calloc(count, sizeof(struct radius_attr_data));
        if (nclass == NULL)
                return;
 
index 185ed4f09c97430049cfd7f0bd58d469b52ef78e..b9e096c459523b87df36647ec2b19b3ce2b6292b 100644 (file)
@@ -858,7 +858,7 @@ static struct wpa_scan_results * wpa_driver_ndis_get_scan_results(void *priv)
                os_free(b);
                return NULL;
        }
-       results->res = os_zalloc(count * sizeof(struct wpa_scan_res *));
+       results->res = os_calloc(count, sizeof(struct wpa_scan_res *));
        if (results->res == NULL) {
                os_free(results);
                os_free(b);
index f560aff5f7c878490012cf11a06a8e6ec42e9e15..211a15af740c692b30caf9dfe5da54b6773a4997 100644 (file)
@@ -4843,7 +4843,8 @@ static int phy_info_handler(struct nl_msg *msg, void *arg)
                        mode->num_channels++;
                }
 
-               mode->channels = os_zalloc(mode->num_channels * sizeof(struct hostapd_channel_data));
+               mode->channels = os_calloc(mode->num_channels,
+                                          sizeof(struct hostapd_channel_data));
                if (!mode->channels)
                        return NL_SKIP;
 
@@ -4905,7 +4906,7 @@ static int phy_info_handler(struct nl_msg *msg, void *arg)
                        mode->num_rates++;
                }
 
-               mode->rates = os_zalloc(mode->num_rates * sizeof(int));
+               mode->rates = os_calloc(mode->num_rates, sizeof(int));
                if (!mode->rates)
                        return NL_SKIP;
 
index c8916f06136ef75f81faa72078cbce562e5eeedf..9481cbf8a056059ae58fd6573de8fde175c228a8 100644 (file)
@@ -152,7 +152,7 @@ wpa_driver_privsep_get_scan_results2(void *priv)
                return NULL;
        }
 
-       results->res = os_zalloc(num * sizeof(struct wpa_scan_res *));
+       results->res = os_calloc(num, sizeof(struct wpa_scan_res *));
        if (results->res == NULL) {
                os_free(results);
                os_free(buf);
index f011651fe803a62d6f3810b04c1687328878be61..7a96b9ba934e21f1fee6b0e0ec59e295bd15284c 100644 (file)
@@ -1478,7 +1478,7 @@ static struct wpa_scan_results * wpa_driver_test_get_scan_results2(void *priv)
        if (res == NULL)
                return NULL;
 
-       res->res = os_zalloc(drv->num_scanres * sizeof(struct wpa_scan_res *));
+       res->res = os_calloc(drv->num_scanres, sizeof(struct wpa_scan_res *));
        if (res->res == NULL) {
                os_free(res);
                return NULL;
@@ -2570,15 +2570,14 @@ wpa_driver_test_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
 
        *num_modes = 3;
        *flags = 0;
-       modes = os_zalloc(*num_modes * sizeof(struct hostapd_hw_modes));
+       modes = os_calloc(*num_modes, sizeof(struct hostapd_hw_modes));
        if (modes == NULL)
                return NULL;
        modes[0].mode = HOSTAPD_MODE_IEEE80211G;
        modes[0].num_channels = 11;
        modes[0].num_rates = 12;
-       modes[0].channels =
-               os_zalloc(11 * sizeof(struct hostapd_channel_data));
-       modes[0].rates = os_zalloc(modes[0].num_rates * sizeof(int));
+       modes[0].channels = os_calloc(11, sizeof(struct hostapd_channel_data));
+       modes[0].rates = os_calloc(modes[0].num_rates, sizeof(int));
        if (modes[0].channels == NULL || modes[0].rates == NULL)
                goto fail;
        for (i = 0; i < 11; i++) {
@@ -2602,9 +2601,8 @@ wpa_driver_test_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
        modes[1].mode = HOSTAPD_MODE_IEEE80211B;
        modes[1].num_channels = 11;
        modes[1].num_rates = 4;
-       modes[1].channels =
-               os_zalloc(11 * sizeof(struct hostapd_channel_data));
-       modes[1].rates = os_zalloc(modes[1].num_rates * sizeof(int));
+       modes[1].channels = os_calloc(11, sizeof(struct hostapd_channel_data));
+       modes[1].rates = os_calloc(modes[1].num_rates, sizeof(int));
        if (modes[1].channels == NULL || modes[1].rates == NULL)
                goto fail;
        for (i = 0; i < 11; i++) {
@@ -2620,8 +2618,8 @@ wpa_driver_test_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
        modes[2].mode = HOSTAPD_MODE_IEEE80211A;
        modes[2].num_channels = 1;
        modes[2].num_rates = 8;
-       modes[2].channels = os_zalloc(sizeof(struct hostapd_channel_data));
-       modes[2].rates = os_zalloc(modes[2].num_rates * sizeof(int));
+       modes[2].channels = os_calloc(1, sizeof(struct hostapd_channel_data));
+       modes[2].rates = os_calloc(modes[2].num_rates, sizeof(int));
        if (modes[2].channels == NULL || modes[2].rates == NULL)
                goto fail;
        modes[2].channels[0].chan = 60;
index ace397491128987d5e7f777261c9c74c449a1e3a..858367cfc874bca592a68aceaea14a3ec7c356f2 100644 (file)
@@ -78,8 +78,8 @@ static void radius_msg_set_hdr(struct radius_msg *msg, u8 code, u8 identifier)
 
 static int radius_msg_initialize(struct radius_msg *msg)
 {
-       msg->attr_pos =
-               os_zalloc(RADIUS_DEFAULT_ATTR_COUNT * sizeof(*msg->attr_pos));
+       msg->attr_pos = os_calloc(RADIUS_DEFAULT_ATTR_COUNT,
+                                 sizeof(*msg->attr_pos));
        if (msg->attr_pos == NULL)
                return -1;
 
@@ -1534,7 +1534,7 @@ int radius_copy_class(struct radius_class_data *dst,
        if (src->attr == NULL)
                return 0;
 
-       dst->attr = os_zalloc(src->count * sizeof(struct radius_attr_data));
+       dst->attr = os_calloc(src->count, sizeof(struct radius_attr_data));
        if (dst->attr == NULL)
                return -1;
 
index a417b3ccec821bf61346b183b3503b69e5a0ca05..9ce4545e0237636ac2445554a1e5c8f0e6c1905e 100644 (file)
@@ -170,7 +170,7 @@ static char ** get_bssid_list(int s)
        if (bssid == NULL)
                return NULL;
 
-       res = os_zalloc((len / ETH_ALEN + 1) * sizeof(char *));
+       res = os_calloc(len / ETH_ALEN + 1, sizeof(char *));
        if (res == NULL)
                return NULL;
        for (i = 0; i < len / ETH_ALEN; i++) {
@@ -208,7 +208,7 @@ static char ** get_sta_list(int s, const u8 *bssid, int add_bcast)
        if (addr == NULL)
                return NULL;
 
-       res = os_zalloc((len / ETH_ALEN + 1 + add_bcast) * sizeof(char *));
+       res = os_calloc(len / ETH_ALEN + 1 + add_bcast, sizeof(char *));
        if (res == NULL)
                return NULL;
        for (i = 0; i < len / ETH_ALEN; i++) {
@@ -623,7 +623,7 @@ static char ** complete_get_sta_counter(int s, const char *str, int pos)
        case 1:
                /* counter list */
                count = sizeof(sta_counters) / sizeof(sta_counters[0]);
-               res = os_zalloc(count * sizeof(char *));
+               res = os_calloc(count, sizeof(char *));
                if (res == NULL)
                        return NULL;
                for (i = 0; sta_counters[i].name; i++) {
@@ -722,7 +722,7 @@ static char ** complete_get_bss_counter(int s, const char *str, int pos)
        case 1:
                /* counter list */
                count = sizeof(bss_counters) / sizeof(bss_counters[0]);
-               res = os_zalloc(count * sizeof(char *));
+               res = os_calloc(count, sizeof(char *));
                if (res == NULL)
                        return NULL;
                for (i = 0; bss_counters[i].name; i++) {
@@ -836,7 +836,7 @@ static char ** complete_get_tdls_counter(int s, const char *str, int pos)
        case 1:
                /* counter list */
                count = sizeof(tdls_counters) / sizeof(tdls_counters[0]);
-               res = os_zalloc(count * sizeof(char *));
+               res = os_calloc(count, sizeof(char *));
                if (res == NULL)
                        return NULL;
                for (i = 0; tdls_counters[i].name; i++) {
@@ -972,7 +972,7 @@ static char ** complete_inject(int s, const char *str, int pos)
        case 1:
                /* frame list */
                count = sizeof(inject_frames) / sizeof(inject_frames[0]);
-               res = os_zalloc(count * sizeof(char *));
+               res = os_calloc(count, sizeof(char *));
                if (res == NULL)
                        break;
                for (i = 0; inject_frames[i].name; i++) {
@@ -982,7 +982,7 @@ static char ** complete_inject(int s, const char *str, int pos)
                }
                break;
        case 2:
-               res = os_zalloc(5 * sizeof(char *));
+               res = os_calloc(5, sizeof(char *));
                if (res == NULL)
                        break;
                res[0] = os_strdup("normal");
@@ -999,7 +999,7 @@ static char ** complete_inject(int s, const char *str, int pos)
                        break;
                break;
        case 3:
-               res = os_zalloc(3 * sizeof(char *));
+               res = os_calloc(3, sizeof(char *));
                if (res == NULL)
                        break;
                res[0] = os_strdup("ap");
@@ -1122,7 +1122,7 @@ static char ** complete_send(int s, const char *str, int pos)
 
        switch (arg) {
        case 1:
-               res = os_zalloc(5 * sizeof(char *));
+               res = os_calloc(5, sizeof(char *));
                if (res == NULL)
                        break;
                res[0] = os_strdup("normal");
@@ -1299,7 +1299,7 @@ static char ** complete_info_sta(int s, const char *str, int pos)
        case 1:
                /* counter list */
                count = sizeof(sta_infos) / sizeof(sta_infos[0]);
-               res = os_zalloc(count * sizeof(char *));
+               res = os_calloc(count, sizeof(char *));
                if (res == NULL)
                        return NULL;
                for (i = 0; sta_infos[i].name; i++) {
@@ -1404,7 +1404,7 @@ static char ** complete_info_bss(int s, const char *str, int pos)
        case 1:
                /* counter list */
                count = sizeof(bss_infos) / sizeof(bss_infos[0]);
-               res = os_zalloc(count * sizeof(char *));
+               res = os_calloc(count, sizeof(char *));
                if (res == NULL)
                        return NULL;
                for (i = 0; bss_infos[i].name; i++) {
@@ -1584,7 +1584,7 @@ static char ** wlantest_cli_cmd_list(void)
 
        count = sizeof(wlantest_cli_commands) /
                sizeof(wlantest_cli_commands[0]);
-       res = os_zalloc(count * sizeof(char *));
+       res = os_calloc(count, sizeof(char *));
        if (res == NULL)
                return NULL;
 
index 617948293c4e9f82ada9e9c43dd9d5ffd38b8e8f..948e2e4d36f8ff23f44f607f9d9d17c9a7adcb04 100644 (file)
@@ -514,7 +514,7 @@ int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
 #endif /* CONFIG_P2P */
 
        hapd_iface->num_bss = conf->num_bss;
-       hapd_iface->bss = os_zalloc(conf->num_bss *
+       hapd_iface->bss = os_calloc(conf->num_bss,
                                    sizeof(struct hostapd_data *));
        if (hapd_iface->bss == NULL) {
                wpa_supplicant_ap_deinit(wpa_s);
index aeb6aba723bb60088e220ab3cc5b7a57a2bc5265..18d74bc7440b427a33a30d6cd580aa1f20735589 100644 (file)
@@ -907,7 +907,7 @@ static int * wpa_config_parse_freqs(const struct parse_data *data,
 
        used = 0;
        len = 10;
-       freqs = os_zalloc((len + 1) * sizeof(int));
+       freqs = os_calloc(len + 1, sizeof(int));
        if (freqs == NULL)
                return NULL;
 
@@ -2107,7 +2107,7 @@ char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys)
 
        get_keys = get_keys && ssid->export_keys;
 
-       props = os_zalloc(sizeof(char *) * ((2 * NUM_SSID_FIELDS) + 1));
+       props = os_calloc(2 * NUM_SSID_FIELDS + 1, sizeof(char *));
        if (!props)
                return NULL;
 
index cbe821a1b3c936cd25747b1dc5c696b48849255b..1b54d5d9680e38a200bc19f888225173f633dda8 100644 (file)
@@ -871,7 +871,7 @@ dbus_bool_t wpas_dbus_getter_interfaces(DBusMessageIter *iter,
        for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
                num++;
 
-       paths = os_zalloc(num * sizeof(char*));
+       paths = os_calloc(num, sizeof(char *));
        if (!paths) {
                dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
                return FALSE;
@@ -2787,7 +2787,7 @@ dbus_bool_t wpas_dbus_getter_bsss(DBusMessageIter *iter, DBusError *error,
        unsigned int i = 0;
        dbus_bool_t success = FALSE;
 
-       paths = os_zalloc(wpa_s->num_bss * sizeof(char *));
+       paths = os_calloc(wpa_s->num_bss, sizeof(char *));
        if (!paths) {
                dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
                return FALSE;
@@ -2850,7 +2850,7 @@ dbus_bool_t wpas_dbus_getter_networks(DBusMessageIter *iter, DBusError *error,
                if (!network_is_persistent_group(ssid))
                        num++;
 
-       paths = os_zalloc(num * sizeof(char *));
+       paths = os_calloc(num, sizeof(char *));
        if (!paths) {
                dbus_set_error(error, DBUS_ERROR_NO_MEMORY, "no memory");
                return FALSE;
index f4541f73a8039816b408fc95efa8deb2b230552e..3d31c8994139c688b71a594d0a875b56ceff8aca 100644 (file)
@@ -1049,7 +1049,7 @@ dbus_bool_t wpas_dbus_getter_p2p_peers(DBusMessageIter *iter, DBusError *error,
         * Now construct the peer object paths in a form suitable for
         * array_property_getter helper below.
         */
-       peer_obj_paths = os_zalloc(num * sizeof(char *));
+       peer_obj_paths = os_calloc(num, sizeof(char *));
 
        if (!peer_obj_paths) {
                out_of_mem = 1;
@@ -1509,7 +1509,7 @@ dbus_bool_t wpas_dbus_getter_persistent_groups(DBusMessageIter *iter,
                if (network_is_persistent_group(ssid))
                        num++;
 
-       paths = os_zalloc(num * sizeof(char *));
+       paths = os_calloc(num, sizeof(char *));
        if (!paths) {
                dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
                return FALSE;
@@ -1816,7 +1816,7 @@ dbus_bool_t wpas_dbus_getter_p2p_group_members(DBusMessageIter *iter,
 
        num_members = p2p_get_group_num_members(wpa_s->p2p_group);
 
-       paths = os_zalloc(num_members * sizeof(char *));
+       paths = os_calloc(num_members, sizeof(char *));
        if (!paths)
                goto out_of_memory;
 
index ebc668b84a1c98b19c4539b57584c9fa101272cc..ea720d21a283d6137f418f8c6ce295a57b53b005 100644 (file)
@@ -330,7 +330,7 @@ static const u8 * nai_realm_parse_realm(struct nai_realm *r, const u8 *pos,
                wpa_printf(MSG_DEBUG, "No room for EAP Methods");
                return NULL;
        }
-       r->eap = os_zalloc(r->eap_count * sizeof(struct nai_realm_eap));
+       r->eap = os_calloc(r->eap_count, sizeof(struct nai_realm_eap));
        if (r->eap == NULL)
                return NULL;
 
@@ -366,7 +366,7 @@ static struct nai_realm * nai_realm_parse(struct wpabuf *anqp, u16 *count)
                return NULL;
        }
 
-       realm = os_zalloc(num * sizeof(struct nai_realm));
+       realm = os_calloc(num, sizeof(struct nai_realm));
        if (realm == NULL)
                return NULL;
 
index a82cb95b08a4cb0dcacf3d2ccb2a3a66cea81213..433872828918f317f3b6263c0092bdcc6eb23916 100644 (file)
@@ -802,7 +802,7 @@ static void wpa_setband_scan_freqs_list(struct wpa_supplicant *wpa_s,
                return;
        }
 
-       params->freqs = os_zalloc((mode->num_channels + 1) * sizeof(int));
+       params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
        if (params->freqs == NULL)
                return;
        for (count = 0, i = 0; i < mode->num_channels; i++) {
index ec84be20275aa256363eb38ef13d6e8560020cf5..e9c0b9c4a805464f01a762b08e16ae0fdfd99b5f 100644 (file)
@@ -240,7 +240,7 @@ static char ** cli_txt_list_array(struct dl_list *txt_list)
        char **res;
        struct cli_txt_entry *e;
 
-       res = os_zalloc((count + 1) * sizeof(char *));
+       res = os_calloc(count + 1, sizeof(char *));
        if (res == NULL)
                return NULL;
 
@@ -3392,7 +3392,7 @@ static char ** wpa_list_cmd_list(void)
        int i, count;
 
        count = sizeof(wpa_cli_commands) / sizeof(wpa_cli_commands[0]);
-       res = os_zalloc(count * sizeof(char *));
+       res = os_calloc(count, sizeof(char *));
        if (res == NULL)
                return NULL;