From 2c60ca73912fe30344df072ca6447f1a4dcdb67b Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sun, 19 Feb 2012 16:44:30 +0200 Subject: [PATCH] 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 --- wpa_supplicant/config.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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;