提交 df753c85 编写于 作者: J Ján Tomko

cpu: use g_strdup instead of VIR_STRDUP

Replace all occurrences of
  if (VIR_STRDUP(a, b) < 0)
     /* effectively dead code */
with:
  a = g_strdup(b);
Signed-off-by: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 17561eb3
......@@ -78,12 +78,13 @@ virCPUarmBaseline(virCPUDefPtr *cpus,
{
virCPUDefPtr cpu = NULL;
if (VIR_ALLOC(cpu) < 0 ||
VIR_STRDUP(cpu->model, cpus[0]->model) < 0) {
if (VIR_ALLOC(cpu) < 0) {
virCPUDefFree(cpu);
return NULL;
}
cpu->model = g_strdup(cpus[0]->model);
cpu->type = VIR_CPU_TYPE_GUEST;
cpu->match = VIR_CPU_MATCH_EXACT;
......
......@@ -188,8 +188,7 @@ ppc64ModelCopy(const struct ppc64_model *model)
if (VIR_ALLOC(copy) < 0)
goto error;
if (VIR_STRDUP(copy->name, model->name) < 0)
goto error;
copy->name = g_strdup(model->name);
if (ppc64DataCopy(&copy->data, &model->data) < 0)
goto error;
......@@ -287,8 +286,7 @@ ppc64VendorParse(xmlXPathContextPtr ctxt G_GNUC_UNUSED,
if (VIR_ALLOC(vendor) < 0)
return -1;
if (VIR_STRDUP(vendor->name, name) < 0)
goto cleanup;
vendor->name = g_strdup(name);
if (ppc64VendorFind(map, vendor->name)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
......@@ -324,8 +322,7 @@ ppc64ModelParse(xmlXPathContextPtr ctxt,
if (VIR_ALLOC(model) < 0)
goto cleanup;
if (VIR_STRDUP(model->name, name) < 0)
goto cleanup;
model->name = g_strdup(name);
if (ppc64ModelFind(map, model->name)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
......@@ -620,10 +617,9 @@ ppc64DriverDecode(virCPUDefPtr cpu,
goto cleanup;
}
if (VIR_STRDUP(cpu->model, model->name) < 0 ||
(model->vendor && VIR_STRDUP(cpu->vendor, model->vendor->name) < 0)) {
goto cleanup;
}
cpu->model = g_strdup(model->name);
if (model->vendor)
cpu->vendor = g_strdup(model->vendor->name);
ret = 0;
......@@ -765,12 +761,13 @@ virCPUppc64Baseline(virCPUDefPtr *cpus,
}
}
if (VIR_ALLOC(cpu) < 0 ||
VIR_STRDUP(cpu->model, model->name) < 0)
if (VIR_ALLOC(cpu) < 0)
goto error;
if (vendor && VIR_STRDUP(cpu->vendor, vendor->name) < 0)
goto error;
cpu->model = g_strdup(model->name);
if (vendor)
cpu->vendor = g_strdup(vendor->name);
cpu->type = VIR_CPU_TYPE_GUEST;
cpu->match = VIR_CPU_MATCH_EXACT;
......@@ -801,10 +798,8 @@ virCPUppc64DriverGetModels(char ***models)
if (VIR_ALLOC_N(*models, map->nmodels + 1) < 0)
goto error;
for (i = 0; i < map->nmodels; i++) {
if (VIR_STRDUP((*models)[i], map->models[i]->name) < 0)
goto error;
}
for (i = 0; i < map->nmodels; i++)
(*models)[i] = g_strdup(map->models[i]->name);
}
ret = map->nmodels;
......
......@@ -775,16 +775,18 @@ x86DataToCPU(const virCPUx86Data *data,
virCPUx86Data modelData = VIR_CPU_X86_DATA_INIT;
virCPUx86VendorPtr vendor;
if (VIR_ALLOC(cpu) < 0 ||
VIR_STRDUP(cpu->model, model->name) < 0 ||
x86DataCopy(&copy, data) < 0 ||
x86DataCopy(&modelData, &model->data) < 0)
if (VIR_ALLOC(cpu) < 0)
goto error;
if ((vendor = x86DataToVendor(&copy, map)) &&
VIR_STRDUP(cpu->vendor, vendor->name) < 0)
cpu->model = g_strdup(model->name);
if (x86DataCopy(&copy, data) < 0 ||
x86DataCopy(&modelData, &model->data) < 0)
goto error;
if ((vendor = x86DataToVendor(&copy, map)))
cpu->vendor = g_strdup(vendor->name);
x86DataSubtract(&copy, &modelData);
x86DataSubtract(&modelData, data);
......@@ -862,8 +864,7 @@ x86VendorParse(xmlXPathContextPtr ctxt,
if (VIR_ALLOC(vendor) < 0)
goto cleanup;
if (VIR_STRDUP(vendor->name, name) < 0)
goto cleanup;
vendor->name = g_strdup(name);
if (x86VendorFind(map, vendor->name)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
......@@ -1062,8 +1063,7 @@ x86FeatureParse(xmlXPathContextPtr ctxt,
feature->migratable = true;
if (VIR_STRDUP(feature->name, name) < 0)
goto cleanup;
feature->name = g_strdup(name);
if (x86FeatureFind(map, feature->name)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
......@@ -1177,9 +1177,12 @@ x86ModelCopy(virCPUx86ModelPtr model)
{
virCPUx86ModelPtr copy;
if (VIR_ALLOC(copy) < 0 ||
VIR_STRDUP(copy->name, model->name) < 0 ||
x86ModelCopySignatures(copy, model) < 0 ||
if (VIR_ALLOC(copy) < 0)
return NULL;
copy->name = g_strdup(model->name);
if (x86ModelCopySignatures(copy, model) < 0 ||
x86DataCopy(&copy->data, &model->data) < 0) {
x86ModelFree(copy);
return NULL;
......@@ -1517,8 +1520,7 @@ x86ModelParse(xmlXPathContextPtr ctxt,
if (!(model = x86ModelNew()))
goto cleanup;
if (VIR_STRDUP(model->name, name) < 0)
goto cleanup;
model->name = g_strdup(name);
if (x86ModelParseAncestor(model, ctxt, map) < 0)
goto cleanup;
......@@ -2210,8 +2212,8 @@ x86Decode(virCPUDefPtr cpu,
}
}
if (vendor && VIR_STRDUP(cpu->vendor, vendor->name) < 0)
goto cleanup;
if (vendor)
cpu->vendor = g_strdup(vendor->name);
sigs = x86FormatSignatures(model);
......@@ -2947,8 +2949,7 @@ x86UpdateHostModel(virCPUDefPtr guest,
if (guest->vendor_id) {
VIR_FREE(updated->vendor_id);
if (VIR_STRDUP(updated->vendor_id, guest->vendor_id) < 0)
goto cleanup;
updated->vendor_id = g_strdup(guest->vendor_id);
}
for (i = 0; i < guest->nfeatures; i++) {
......@@ -3134,10 +3135,8 @@ virCPUx86GetModels(char ***models)
if (VIR_ALLOC_N(*models, map->nmodels + 1) < 0)
goto error;
for (i = 0; i < map->nmodels; i++) {
if (VIR_STRDUP((*models)[i], map->models[i]->name) < 0)
goto error;
}
for (i = 0; i < map->nmodels; i++)
(*models)[i] = g_strdup(map->models[i]->name);
}
return map->nmodels;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册