[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v3 04/34] Adapt to VIR_STRDUP and VIR_STRNDUP in src/cpu/*



---
 src/cpu/cpu_generic.c |  8 ++++----
 src/cpu/cpu_map.c     |  3 ++-
 src/cpu/cpu_powerpc.c | 13 ++++++-------
 src/cpu/cpu_x86.c     | 10 +++++-----
 4 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/src/cpu/cpu_generic.c b/src/cpu/cpu_generic.c
index 9d5117f..7e3eda2 100644
--- a/src/cpu/cpu_generic.c
+++ b/src/cpu/cpu_generic.c
@@ -28,7 +28,7 @@
 #include "virhash.h"
 #include "cpu.h"
 #include "cpu_generic.h"
-
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_CPU
 
@@ -131,7 +131,7 @@ genericBaseline(virCPUDefPtr *cpus,
     }
 
     if (VIR_ALLOC(cpu) < 0 ||
-        !(cpu->model = strdup(cpus[0]->model)) ||
+        VIR_STRDUP(cpu->model, cpus[0]->model) < 0 ||
         VIR_ALLOC_N(features, cpus[0]->nfeatures) < 0)
         goto no_memory;
 
@@ -183,8 +183,8 @@ genericBaseline(virCPUDefPtr *cpus,
         if (!features[i].name)
             continue;
 
-        if (!(cpu->features[j++].name = strdup(features[i].name)))
-            goto no_memory;
+        if (VIR_STRDUP(cpu->features[j++].name, features[i].name) < 0)
+            goto error;
     }
 
 cleanup:
diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c
index 015be2e..7c2bdec 100644
--- a/src/cpu/cpu_map.c
+++ b/src/cpu/cpu_map.c
@@ -27,6 +27,7 @@
 #include "cpu.h"
 #include "cpu_map.h"
 #include "configmake.h"
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_CPU
 
@@ -149,7 +150,7 @@ cpuMapOverride(const char *path)
 {
     char *map;
 
-    if (!(map = strdup(path)))
+    if (VIR_STRDUP(map, path) < 0)
         return -1;
 
     VIR_FREE(cpumap);
diff --git a/src/cpu/cpu_powerpc.c b/src/cpu/cpu_powerpc.c
index b253db2..d17f9ca 100644
--- a/src/cpu/cpu_powerpc.c
+++ b/src/cpu/cpu_powerpc.c
@@ -29,7 +29,7 @@
 #include "virlog.h"
 #include "viralloc.h"
 #include "cpu.h"
-
+#include "virstring.h"
 #include "cpu_map.h"
 #include "virbuffer.h"
 
@@ -333,9 +333,8 @@ ppcDecode(virCPUDefPtr cpu,
         goto cleanup;
     }
 
-    if (!(cpu->model = strdup(model->name)) ||
-        (model->vendor && !(cpu->vendor = strdup(model->vendor->name)))) {
-        virReportOOMError();
+    if (VIR_STRDUP(cpu->model, model->name) < 0 ||
+        (model->vendor && VIR_STRDUP(cpu->vendor, model->vendor->name) < 0)) {
         goto cleanup;
     }
 
@@ -449,11 +448,11 @@ ppcBaseline(virCPUDefPtr *cpus,
     }
 
     if (VIR_ALLOC(cpu) < 0 ||
-        !(cpu->model = strdup(model->name)))
+        VIR_STRDUP(cpu->model, model->name) < 0)
         goto no_memory;
 
-    if (vendor && !(cpu->vendor = strdup(vendor->name)))
-        goto no_memory;
+    if (vendor && VIR_STRDUP(cpu->vendor, vendor->name) < 0)
+        goto error;
 
     cpu->type = VIR_CPU_TYPE_GUEST;
     cpu->match = VIR_CPU_MATCH_EXACT;
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 14d525e..5d479c2 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -449,13 +449,13 @@ x86DataToCPU(const union cpuData *data,
     const struct x86_vendor *vendor;
 
     if (VIR_ALLOC(cpu) < 0 ||
-        !(cpu->model = strdup(model->name)) ||
+        VIR_STRDUP(cpu->model, model->name) < 0 ||
         !(copy = x86DataCopy(data)) ||
         !(modelData = x86DataCopy(model->data)))
         goto no_memory;
 
     if ((vendor = x86DataToVendor(copy, map)) &&
-        !(cpu->vendor = strdup(vendor->name)))
+        VIR_STRDUP(cpu->vendor, vendor->name) < 0)
         goto no_memory;
 
     x86DataSubtract(copy, modelData);
@@ -766,9 +766,9 @@ x86ModelCopy(const struct x86_model *model)
 {
     struct x86_model *copy;
 
-    if (VIR_ALLOC(copy) < 0
-        || !(copy->name = strdup(model->name))
-        || !(copy->data = x86DataCopy(model->data))) {
+    if (VIR_ALLOC(copy) < 0 ||
+        VIR_STRDUP(copy->name, model->name) < 0 ||
+        !(copy->data = x86DataCopy(model->data))) {
         x86ModelFree(copy);
         return NULL;
     }
-- 
1.8.1.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]