]> xenbits.xensource.com Git - libvirt.git/commitdiff
virnetdevopenvswitch: Don't call strlen() twice on the same string
authorAndrea Bolognani <abologna@redhat.com>
Wed, 27 Jan 2016 09:35:17 +0000 (10:35 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Wed, 27 Jan 2016 12:01:24 +0000 (13:01 +0100)
Commit 871e10f fixed a memory corruption error, but called strlen()
twice on the same string to do so. Even though the compiler is
probably smart enough to optimize the second call away, having a
single invocation makes the code slightly cleaner.

Suggested-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virnetdevopenvswitch.c

index db01dcf2c0a45e504498d188b8fb47941c523bd1..9283bbb6d9407d6b01aed8e64fdfd5e97001fa1d 100644 (file)
@@ -207,6 +207,7 @@ int virNetDevOpenvswitchRemovePort(const char *brname ATTRIBUTE_UNUSED, const ch
 int virNetDevOpenvswitchGetMigrateData(char **migrate, const char *ifname)
 {
     virCommandPtr cmd = NULL;
+    size_t len;
     int ret = -1;
 
     cmd = virCommandNewArgList(OVSVSCTL, "--timeout=5", "--if-exists", "get", "Interface",
@@ -223,8 +224,9 @@ int virNetDevOpenvswitchGetMigrateData(char **migrate, const char *ifname)
     }
 
     /* Wipeout the newline, if it exists */
-    if (strlen(*migrate) > 0)
-        (*migrate)[strlen(*migrate) - 1] = '\0';
+    len = strlen(*migrate);
+    if (len > 0)
+        (*migrate)[len - 1] = '\0';
 
     ret = 0;
  cleanup: