--- src/xenxs/xen_sxpr.c | 107 +++++++++++++++++++++------------------------------ src/xenxs/xen_xm.c | 43 ++++++++++----------- 2 files changed, 65 insertions(+), 85 deletions(-) diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c index 9a76d04..7ebaa30 100644 --- a/src/xenxs/xen_sxpr.c +++ b/src/xenxs/xen_sxpr.c @@ -192,8 +192,7 @@ xenParseSxprChar(const char *value, if (value[0] == '/') { def->source.type = VIR_DOMAIN_CHR_TYPE_DEV; - def->source.data.file.path = strdup(value); - if (!def->source.data.file.path) + if (VIR_STRDUP(def->source.data.file.path, value) < 0) goto no_memory; } else { if ((tmp = strchr(value, ':')) != NULL) { @@ -216,13 +215,13 @@ xenParseSxprChar(const char *value, switch (def->source.type) { case VIR_DOMAIN_CHR_TYPE_PTY: if (tty != NULL && - !(def->source.data.file.path = strdup(tty))) + VIR_STRDUP(def->source.data.file.path, tty) < 0) goto no_memory; break; case VIR_DOMAIN_CHR_TYPE_FILE: case VIR_DOMAIN_CHR_TYPE_PIPE: - if (!(def->source.data.file.path = strdup(value))) + if (VIR_STRDUP(def->source.data.file.path, value) < 0) goto no_memory; break; @@ -238,17 +237,14 @@ xenParseSxprChar(const char *value, } if (offset != value && - (def->source.data.tcp.host = strndup(value, - offset - value)) == NULL) + VIR_STRNDUP(def->source.data.tcp.host, value, offset - value) < 0) goto no_memory; offset2 = strchr(offset, ','); - if (offset2 == NULL) - def->source.data.tcp.service = strdup(offset+1); - else - def->source.data.tcp.service = strndup(offset+1, - offset2-(offset+1)); - if (def->source.data.tcp.service == NULL) + + if ((offset2 && VIR_STRNDUP(def->source.data.tcp.service, offset + 1, + offset2 - (offset + 1)) < 0) || + (!offset2 && VIR_STRDUP(def->source.data.tcp.service, offset + 1) < 0)) goto no_memory; if (offset2 && strstr(offset2, ",server")) @@ -268,14 +264,12 @@ xenParseSxprChar(const char *value, } if (offset != value && - (def->source.data.udp.connectHost - = strndup(value, offset - value)) == NULL) + VIR_STRNDUP(def->source.data.udp.connectHost, value, offset - value) < 0) goto no_memory; offset2 = strchr(offset, '@'); if (offset2 != NULL) { - if ((def->source.data.udp.connectService - = strndup(offset + 1, offset2-(offset+1))) == NULL) + if (VIR_STRNDUP(def->source.data.udp.connectService, offset + 1, offset2-(offset+1)) < 0) goto no_memory; offset3 = strchr(offset2, ':'); @@ -286,16 +280,13 @@ xenParseSxprChar(const char *value, } if (offset3 > (offset2 + 1) && - (def->source.data.udp.bindHost - = strndup(offset2 + 1, offset3 - (offset2+1))) == NULL) + VIR_STRNDUP(def->source.data.udp.bindHost, offset2 + 1, offset3 - (offset2+1)) < 0) goto no_memory; - if ((def->source.data.udp.bindService - = strdup(offset3 + 1)) == NULL) + if (VIR_STRDUP(def->source.data.udp.bindService, offset3 + 1) < 0) goto no_memory; } else { - if ((def->source.data.udp.connectService - = strdup(offset + 1)) == NULL) + if (VIR_STRDUP(def->source.data.udp.connectService, offset + 1) < 0) goto no_memory; } } @@ -304,11 +295,9 @@ xenParseSxprChar(const char *value, case VIR_DOMAIN_CHR_TYPE_UNIX: { const char *offset = strchr(value, ','); - if (offset) - def->source.data.nix.path = strndup(value, (offset - value)); - else - def->source.data.nix.path = strdup(value); - if (def->source.data.nix.path == NULL) + + if ((offset && VIR_STRNDUP(def->source.data.nix.path, value, (offset - value)) < 0) || + (!offset && VIR_STRDUP(def->source.data.nix.path, value) < 0)) goto no_memory; if (offset != NULL && @@ -411,7 +400,7 @@ xenParseSxprDisks(virDomainDefPtr def, if (sexpr_lookup(node, "device/tap2") && STRPREFIX(src, "tap:")) { - if (!(disk->driverName = strdup("tap2"))) + if (VIR_STRDUP(disk->driverName, "tap2") < 0) goto no_memory; } else { if (VIR_ALLOC_N(disk->driverName, (offset-src)+1) < 0) @@ -438,7 +427,7 @@ xenParseSxprDisks(virDomainDefPtr def, goto error; } - if (!(driverType = strndup(src, offset - src))) + if (VIR_STRNDUP(driverType, src, offset - src) < 0) goto no_memory; if (STREQ(driverType, "aio")) disk->format = VIR_STORAGE_FILE_RAW; @@ -490,10 +479,9 @@ xenParseSxprDisks(virDomainDefPtr def, } } - if (!(disk->dst = strdup(dst))) + if (VIR_STRDUP(disk->dst, dst) < 0) goto no_memory; - if (src && - !(disk->src = strdup(src))) + if (src && VIR_STRDUP(disk->src, src) < 0) goto no_memory; if (STRPREFIX(disk->dst, "xvd")) @@ -572,25 +560,21 @@ xenParseSxprNets(virDomainDefPtr def, net->type = VIR_DOMAIN_NET_TYPE_BRIDGE; /* XXX virtual network reverse resolve */ - if (tmp && - !(net->data.bridge.brname = strdup(tmp))) + if (tmp &&VIR_STRDUP(net->data.bridge.brname, tmp) < 0) goto no_memory; if (tmp2 && net->type == VIR_DOMAIN_NET_TYPE_BRIDGE && - !(net->script = strdup(tmp2))) + VIR_STRDUP(net->script, tmp2) < 0) goto no_memory; tmp = sexpr_node(node, "device/vif/ip"); - if (tmp && - !(net->data.bridge.ipaddr = strdup(tmp))) + if (tmp && VIR_STRDUP(net->data.bridge.ipaddr, tmp) < 0) goto no_memory; } else { net->type = VIR_DOMAIN_NET_TYPE_ETHERNET; - if (tmp2 && - !(net->script = strdup(tmp2))) + if (tmp2 && VIR_STRDUP(net->script, tmp2) < 0) goto no_memory; tmp = sexpr_node(node, "device/vif/ip"); - if (tmp && - !(net->data.ethernet.ipaddr = strdup(tmp))) + if (tmp && VIR_STRDUP(net->data.ethernet.ipaddr, tmp) < 0) goto no_memory; } @@ -599,7 +583,7 @@ xenParseSxprNets(virDomainDefPtr def, * definition regardless of domain state. If vifname is not * specified, only generate one if domain is active (id != -1). */ if (tmp) { - if (!(net->ifname = strdup(tmp))) + if (VIR_STRDUP(net->ifname, tmp) < 0) goto no_memory; } else if (def->id != -1) { if (virAsprintf(&net->ifname, "vif%d.%d", def->id, vif_index) < 0) @@ -615,13 +599,12 @@ xenParseSxprNets(virDomainDefPtr def, } } - if (model && - !(net->model = strdup(model))) + if (model && VIR_STRDUP(net->model, model) < 0) goto no_memory; if (!model && type && STREQ(type, "netfront") && - !(net->model = strdup("netfront"))) + VIR_STRDUP(net->model, "netfront") < 0) goto no_memory; if (VIR_REALLOC_N(def->nets, def->nnets + 1) < 0) @@ -834,11 +817,11 @@ xenParseSxprGraphicsOld(virDomainDefPtr def, goto error; if (vncPasswd && - !(graphics->data.vnc.auth.passwd = strdup(vncPasswd))) + VIR_STRDUP(graphics->data.vnc.auth.passwd, vncPasswd) < 0) goto no_memory; if (keymap && - !(graphics->data.vnc.keymap = strdup(keymap))) + VIR_STRDUP(graphics->data.vnc.keymap, keymap) < 0) goto no_memory; if (VIR_ALLOC_N(def->graphics, 1) < 0) @@ -857,10 +840,10 @@ xenParseSxprGraphicsOld(virDomainDefPtr def, graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL; if (display && - !(graphics->data.sdl.display = strdup(display))) + VIR_STRDUP(graphics->data.sdl.display, display) < 0) goto no_memory; if (xauth && - !(graphics->data.sdl.xauth = strdup(xauth))) + VIR_STRDUP(graphics->data.sdl.xauth, xauth) < 0) goto no_memory; if (VIR_ALLOC_N(def->graphics, 1) < 0) @@ -926,11 +909,9 @@ xenParseSxprGraphicsNew(virDomainDefPtr def, if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) { const char *display = sexpr_node(node, "device/vfb/display"); const char *xauth = sexpr_node(node, "device/vfb/xauthority"); - if (display && - !(graphics->data.sdl.display = strdup(display))) + if (display && VIR_STRDUP(graphics->data.sdl.display, display) < 0) goto no_memory; - if (xauth && - !(graphics->data.sdl.xauth = strdup(xauth))) + if (xauth && VIR_STRDUP(graphics->data.sdl.xauth, xauth) < 0) goto no_memory; } else { int port; @@ -961,11 +942,11 @@ xenParseSxprGraphicsNew(virDomainDefPtr def, goto error; if (vncPasswd && - !(graphics->data.vnc.auth.passwd = strdup(vncPasswd))) + VIR_STRDUP(graphics->data.vnc.auth.passwd, vncPasswd) < 0) goto no_memory; if (keymap && - !(graphics->data.vnc.keymap = strdup(keymap))) + VIR_STRDUP(graphics->data.vnc.keymap, keymap) < 0) goto no_memory; } @@ -1180,7 +1161,7 @@ xenParseSxpr(const struct sexpr *root, if (!def->os.bootloader && sexpr_has(root, "domain/bootloader") && - (def->os.bootloader = strdup("")) == NULL) + VIR_STRDUP(def->os.bootloader, "") < 0) goto no_memory; if (def->os.bootloader && @@ -1189,7 +1170,7 @@ xenParseSxpr(const struct sexpr *root, goto no_memory; } - if (!(def->os.type = strdup(hvm ? "hvm" : "linux"))) + if (VIR_STRDUP(def->os.type, hvm ? "hvm" : "linux") < 0) goto no_memory; if (def->id != 0) { @@ -1357,17 +1338,17 @@ xenParseSxpr(const struct sexpr *root, virDomainDiskDefPtr disk; if (VIR_ALLOC(disk) < 0) goto no_memory; - if (!(disk->src = strdup(tmp))) { + if (VIR_STRDUP(disk->src, tmp) < 0) { virDomainDiskDefFree(disk); goto no_memory; } disk->type = VIR_DOMAIN_DISK_TYPE_FILE; disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM; - if (!(disk->dst = strdup("hdc"))) { + if (VIR_STRDUP(disk->dst, "hdc") < 0) { virDomainDiskDefFree(disk); goto no_memory; } - if (!(disk->driverName = strdup("file"))) { + if (VIR_STRDUP(disk->driverName, "file") < 0) { virDomainDiskDefFree(disk); goto no_memory; } @@ -1393,17 +1374,17 @@ xenParseSxpr(const struct sexpr *root, virDomainDiskDefPtr disk; if (VIR_ALLOC(disk) < 0) goto no_memory; - if (!(disk->src = strdup(tmp))) { + if (VIR_STRDUP(disk->src, tmp) < 0) { VIR_FREE(disk); goto no_memory; } disk->type = VIR_DOMAIN_DISK_TYPE_FILE; disk->device = VIR_DOMAIN_DISK_DEVICE_FLOPPY; - if (!(disk->dst = strdup(fds[i]))) { + if (VIR_STRDUP(disk->dst, fds[i]) < 0) { virDomainDiskDefFree(disk); goto no_memory; } - if (!(disk->driverName = strdup("file"))) { + if (VIR_STRDUP(disk->driverName, "file") < 0) { virDomainDiskDefFree(disk); goto no_memory; } diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 57ce2e7..7161fac 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -183,7 +183,7 @@ static int xenXMConfigCopyStringInternal(virConfPtr conf, return -1; } - if (!(*value = strdup(val->str))) { + if (VIR_STRDUP(*value, val->str) < 0) { virReportOOMError(); return -1; } @@ -288,7 +288,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, STREQ(str, "hvm")) hvm = 1; - if (!(def->os.type = strdup(hvm ? "hvm" : "xen"))) + if (VIR_STRDUP(def->os.type, hvm ? "hvm" : "xen") < 0) goto no_memory; def->os.arch = @@ -307,7 +307,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, def->os.arch, virDomainVirtTypeToString(def->virtType)); if (defaultMachine != NULL) { - if (!(def->os.machine = strdup(defaultMachine))) + if (VIR_STRDUP(def->os.machine, defaultMachine) < 0) goto no_memory; } @@ -562,7 +562,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (!(tmp = strchr(disk->src, ':'))) goto skipdisk; - if (!(driverType = strndup(disk->src, tmp - disk->src))) + if (VIR_STRNDUP(driverType, disk->src, tmp - disk->src) < 0) goto no_memory; if (STREQ(driverType, "aio")) disk->format = VIR_STORAGE_FILE_RAW; @@ -584,8 +584,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, } /* No source, or driver name, so fix to phy: */ - if (!disk->driverName && - !(disk->driverName = strdup("phy"))) + if (!disk->driverName && VIR_STRDUP(disk->driverName, "phy") < 0) goto no_memory; @@ -637,11 +636,11 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, disk->type = VIR_DOMAIN_DISK_TYPE_FILE; disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM; - if (!(disk->driverName = strdup("file"))) + if (VIR_STRDUP(disk->driverName, "file") < 0) goto no_memory; - if (!(disk->src = strdup(str))) + if (VIR_STRDUP(disk->src, str) < 0) goto no_memory; - if (!(disk->dst = strdup("hdc"))) + if (VIR_STRDUP(disk->dst, "hdc") < 0) goto no_memory; disk->bus = VIR_DOMAIN_DISK_BUS_IDE; disk->readonly = true; @@ -703,7 +702,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, } else if (STRPREFIX(key, "script=")) { int len = nextkey ? (nextkey - data) : strlen(data); VIR_FREE(script); - if (!(script = strndup(data, len))) { + if (VIR_STRNDUP(script, data, len) < 0) { goto no_memory; } } else if (STRPREFIX(key, "model=")) { @@ -764,32 +763,32 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) { if (bridge[0] && - !(net->data.bridge.brname = strdup(bridge))) + VIR_STRDUP(net->data.bridge.brname, bridge) < 0) goto no_memory; if (ip[0] && - !(net->data.bridge.ipaddr = strdup(ip))) + VIR_STRDUP(net->data.bridge.ipaddr, ip) < 0) goto no_memory; } else { if (ip[0] && - !(net->data.ethernet.ipaddr = strdup(ip))) + VIR_STRDUP(net->data.ethernet.ipaddr, ip) < 0) goto no_memory; } if (script && script[0] && - !(net->script = strdup(script))) + VIR_STRDUP(net->script, script) < 0) goto no_memory; if (model[0] && - !(net->model = strdup(model))) + VIR_STRDUP(net->model, model) < 0) goto no_memory; if (!model[0] && type[0] && STREQ(type, "netfront") && - !(net->model = strdup("netfront"))) + VIR_STRDUP(net->model, "netfront") < 0) goto no_memory; if (vifname[0] && - !(net->ifname = strdup(vifname))) + VIR_STRDUP(net->ifname, vifname) < 0) goto no_memory; if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0) @@ -1019,20 +1018,20 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, -1, true) < 0) goto cleanup; } else if (STRPREFIX(key, "vncpasswd=")) { - if (!(graphics->data.vnc.auth.passwd = strdup(key + 10))) + if (VIR_STRDUP(graphics->data.vnc.auth.passwd, key + 10) < 0) goto no_memory; } else if (STRPREFIX(key, "keymap=")) { - if (!(graphics->data.vnc.keymap = strdup(key + 7))) + if (VIR_STRDUP(graphics->data.vnc.keymap, key + 7) < 0) goto no_memory; } else if (STRPREFIX(key, "vncdisplay=")) { graphics->data.vnc.port = strtol(key+11, NULL, 10) + 5900; } } else { if (STRPREFIX(key, "display=")) { - if (!(graphics->data.sdl.display = strdup(key + 8))) + if (VIR_STRDUP(graphics->data.sdl.display, key + 8) < 0) goto no_memory; } else if (STRPREFIX(key, "xauthority=")) { - if (!(graphics->data.sdl.xauth = strdup(key + 11))) + if (VIR_STRDUP(graphics->data.sdl.xauth, key + 11) < 0) goto no_memory; } } @@ -1193,7 +1192,7 @@ int xenXMConfigSetString(virConfPtr conf, const char *setting, const char *str) value->type = VIR_CONF_STRING; value->next = NULL; - if (!(value->str = strdup(str))) { + if (VIR_STRDUP(value->str, str) < 0) { VIR_FREE(value); virReportOOMError(); return -1; -- 1.8.1.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list