]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Clean up array insertion to skip unnecessary memmove
authorJouni Malinen <j@w1.fi>
Sun, 19 Feb 2012 14:44:30 +0000 (16:44 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 19 Feb 2012 14:44:30 +0000 (16:44 +0200)
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 <j@w1.fi>

wpa_supplicant/config.c

index 7ba2df61e31107f3d94c90d87eb9f39151d5eedd..72387f85b3058fc2c22c4da88baecdc7da482e71 100644 (file)
@@ -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;