1
0

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,7 +1561,6 @@ virDomainEventMetadataChangeNew(int id,
return NULL;
ev->type = type;
if (nsuri)
ev->nsuri = g_strdup(nsuri);
return (virObjectEvent *)ev;

View File

@ -583,7 +583,6 @@ 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);
if (def->nsounds > 0) {
@ -1198,7 +1197,6 @@ 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);
return 0;

View File

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

View File

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

View File

@ -939,7 +939,6 @@ 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);
break;
}