src: Avoid needless checks before calling g_strdup()

There are few places where the following pattern occurs:

  if (var)
      other = g_strdup(var);

where @other wasn't initialized before g_strdup(). Checking for
var != NULL is useless in this case, as that's exactly what
g_strdup() does (in which case it returns NULL).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2023-09-18 11:28:31 +02:00
parent 65558eb5cb
commit 732c5f4270
5 changed files with 6 additions and 12 deletions

View File

@ -1561,8 +1561,7 @@ virDomainEventMetadataChangeNew(int id,
return NULL;
ev->type = type;
if (nsuri)
ev->nsuri = g_strdup(nsuri);
ev->nsuri = g_strdup(nsuri);
return (virObjectEvent *)ev;
}

View File

@ -583,8 +583,7 @@ libxlMakeDomBuildInfo(virDomainDef *def,
#endif
/* copy SLIC table path to acpi_firmware */
if (def->os.slic_table)
b_info->u.hvm.acpi_firmware = g_strdup(def->os.slic_table);
b_info->u.hvm.acpi_firmware = g_strdup(def->os.slic_table);
if (def->nsounds > 0) {
/*
@ -1198,8 +1197,7 @@ libxlMakeDisk(virDomainDiskDef *l_disk, libxl_device_disk *x_disk)
return -1;
}
if (l_disk->domain_name)
x_disk->backend_domname = g_strdup(l_disk->domain_name);
x_disk->backend_domname = g_strdup(l_disk->domain_name);
return 0;
}

View File

@ -67,8 +67,7 @@ lxcCreateFSDef(int type,
def->type = type;
def->accessmode = VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH;
if (src)
def->src->path = g_strdup(src);
def->src->path = g_strdup(src);
def->dst = g_strdup(dst);
def->readonly = readonly;
def->usage = usage;

View File

@ -2960,8 +2960,7 @@ qemuMonitorJSONGetMigrationStatsReply(virJSONValue *reply,
case QEMU_MONITOR_MIGRATION_STATUS_ERROR:
if (error) {
tmp = virJSONValueObjectGetString(ret, "error-desc");
if (tmp)
*error = g_strdup(tmp);
*error = g_strdup(tmp);
}
break;

View File

@ -939,8 +939,7 @@ int virConfGetValueStringList(virConf *conf,
case VIR_CONF_STRING:
if (compatString) {
*values = g_new0(char *, cval->str ? 2 : 1);
if (cval->str)
(*values)[0] = g_strdup(cval->str);
(*values)[0] = g_strdup(cval->str);
break;
}
G_GNUC_FALLTHROUGH;