Skip to content

Commit

Permalink
g_strdup(NULL) returns NULL; simplify
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information
Markus Armbruster authored and stefanhaRH committed Jan 30, 2013
1 parent 6528499 commit c64f50d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 23 deletions.
6 changes: 1 addition & 5 deletions hw/9pfs/virtio-9p-device.c
Expand Up @@ -85,11 +85,7 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
}

s->ctx.export_flags = fse->export_flags;
if (fse->path) {
s->ctx.fs_root = g_strdup(fse->path);
} else {
s->ctx.fs_root = NULL;
}
s->ctx.fs_root = g_strdup(fse->path);
s->ctx.exops.get_st_gen = NULL;
len = strlen(conf->tag);
if (len > MAX_TAG_LEN - 1) {
Expand Down
4 changes: 1 addition & 3 deletions hw/block-common.c
Expand Up @@ -18,9 +18,7 @@ void blkconf_serial(BlockConf *conf, char **serial)
if (!*serial) {
/* try to fall back to value set with legacy -drive serial=... */
dinfo = drive_get_by_blockdev(conf->bs);
if (dinfo->serial) {
*serial = g_strdup(dinfo->serial);
}
*serial = g_strdup(dinfo->serial);
}
}

Expand Down
4 changes: 1 addition & 3 deletions net/net.c
Expand Up @@ -566,9 +566,7 @@ static int net_init_nic(const NetClientOptions *opts, const char *name,
assert(peer);
nd->netdev = peer;
}
if (name) {
nd->name = g_strdup(name);
}
nd->name = g_strdup(name);
if (nic->has_model) {
nd->model = g_strdup(nic->model);
}
Expand Down
8 changes: 2 additions & 6 deletions slirp/slirp.c
Expand Up @@ -225,12 +225,8 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
pstrcpy(slirp->client_hostname, sizeof(slirp->client_hostname),
vhostname);
}
if (tftp_path) {
slirp->tftp_prefix = g_strdup(tftp_path);
}
if (bootfile) {
slirp->bootp_filename = g_strdup(bootfile);
}
slirp->tftp_prefix = g_strdup(tftp_path);
slirp->bootp_filename = g_strdup(bootfile);
slirp->vdhcp_startaddr = vdhcp_start;
slirp->vnameserver_addr = vnameserver;

Expand Down
8 changes: 2 additions & 6 deletions util/qemu-option.c
Expand Up @@ -643,9 +643,7 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value,
QTAILQ_INSERT_TAIL(&opts->head, opt, next);
}
opt->desc = desc;
if (value) {
opt->str = g_strdup(value);
}
opt->str = g_strdup(value);
qemu_opt_parse(opt, &local_err);
if (error_is_set(&local_err)) {
error_propagate(errp, local_err);
Expand Down Expand Up @@ -792,9 +790,7 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
}
}
opts = g_malloc0(sizeof(*opts));
if (id) {
opts->id = g_strdup(id);
}
opts->id = g_strdup(id);
opts->list = list;
loc_save(&opts->loc);
QTAILQ_INIT(&opts->head);
Expand Down

0 comments on commit c64f50d

Please sign in to comment.