From: Jouni Malinen Date: Sun, 19 Feb 2012 14:44:30 +0000 (+0200) Subject: Clean up array insertion to skip unnecessary memmove X-Git-Tag: hostap_2_0~849 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c60ca73912fe30344df072ca6447f1a4dcdb67b;p=thirdparty%2Fhostap.git Clean up array insertion to skip unnecessary memmove The previous elements need to be moved only if we are inserting the new network in the middle of the list. While the memmove of zero bytes at the end of the array does not cause real problems, some static analyzers complain about this, so in addition to slightly optimized implementation, this removes some analyzer warnings, too. Signed-hostap: Jouni Malinen --- diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c index 7ba2df61e..72387f85b 100644 --- a/wpa_supplicant/config.c +++ b/wpa_supplicant/config.c @@ -1659,13 +1659,14 @@ int wpa_config_add_prio_network(struct wpa_config *config, return -1; for (prio = 0; prio < config->num_prio; prio++) { - if (nlist[prio]->priority < ssid->priority) + if (nlist[prio]->priority < ssid->priority) { + os_memmove(&nlist[prio + 1], &nlist[prio], + (config->num_prio - prio) * + sizeof(struct wpa_ssid *)); break; + } } - os_memmove(&nlist[prio + 1], &nlist[prio], - (config->num_prio - prio) * sizeof(struct wpa_ssid *)); - nlist[prio] = ssid; config->num_prio++; config->pssid = nlist;