When virAsprintf was changed from a function to a macro
reporting OOM error in
dc6f2da, it was documented as returning
0 on success. This is incorrect, it returns the number of bytes
written as asprintf does.
Some of the functions were converted to use virAsprintf's return
value directly, changing the return value on success from 0 to >= 0.
For most of these, this is not a problem, but the change in
virPCIDriverDir breaks PCI passthrough.
The return value check in virhashtest pre-dates virAsprintf OOM
conversion.
vmwareMakePath seems to be unused.
}
}
- return virAsprintf(&net->info.alias, "net%d", idx);
+ if (virAsprintf(&net->info.alias, "net%d", idx) < 0)
+ return -1;
+ return 0;
}
}
}
- return virAsprintf(&redirdev->info.alias, "redir%d", idx);
+ if (virAsprintf(&redirdev->info.alias, "redir%d", idx) < 0)
+ return -1;
+ return 0;
}
{
const char *prefix = virDomainControllerTypeToString(controller->type);
- return virAsprintf(&controller->info.alias, "%s%d", prefix, controller->idx);
+ if (virAsprintf(&controller->info.alias, "%s%d", prefix,
+ controller->idx) < 0)
+ return -1;
+ return 0;
}
static ssize_t
monConfig->type = VIR_DOMAIN_CHR_TYPE_UNIX;
monConfig->data.nix.listen = true;
- return virAsprintf(&monConfig->data.nix.path, "%s/%s.monitor",
- cfg->libDir, vm);
+ if (virAsprintf(&monConfig->data.nix.path, "%s/%s.monitor",
+ cfg->libDir, vm) < 0)
+ return -1;
+ return 0;
}
const char *file)
{
- return virAsprintf(pf_sysfs_device_link, NET_SYSFS "%s/%s", ifname, file);
+ if (virAsprintf(pf_sysfs_device_link, NET_SYSFS "%s/%s", ifname, file) < 0)
+ return -1;
+ return 0;
}
static int
const char *file)
{
- return virAsprintf(pf_sysfs_device_link, NET_SYSFS "%s/device/%s",
- ifname, file);
+ if (virAsprintf(pf_sysfs_device_link, NET_SYSFS "%s/device/%s", ifname,
+ file) < 0)
+ return -1;
+ return 0;
}
/**
{
VIR_FREE(*buffer);
- return virAsprintf(buffer, PCI_SYSFS "drivers/%s", driver);
+ if (virAsprintf(buffer, PCI_SYSFS "drivers/%s", driver) < 0)
+ return -1;
+ return 0;
}
{
VIR_FREE(*buffer);
- return virAsprintf(buffer, PCI_SYSFS "drivers/%s/%s", driver, file);
+ if (virAsprintf(buffer, PCI_SYSFS "drivers/%s/%s", driver, file) < 0)
+ return -1;
+ return 0;
}
{
VIR_FREE(*buffer);
- return virAsprintf(buffer, PCI_SYSFS "devices/%s/%s", device, file);
+ if (virAsprintf(buffer, PCI_SYSFS "devices/%s/%s", device, file) < 0)
+ return -1;
+ return 0;
}
int
virPCIGetSysfsFile(char *virPCIDeviceName, char **pci_sysfs_device_link)
{
- return virAsprintf(pci_sysfs_device_link, PCI_SYSFS "devices/%s",
- virPCIDeviceName);
+ if (virAsprintf(pci_sysfs_device_link, PCI_SYSFS "devices/%s",
+ virPCIDeviceName) < 0)
+ return -1;
+ return 0;
}
int
virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddressPtr dev,
char **pci_sysfs_device_link)
{
- return virAsprintf(pci_sysfs_device_link,
- PCI_SYSFS "devices/%04x:%02x:%02x.%x", dev->domain,
- dev->bus, dev->slot, dev->function);
+ if (virAsprintf(pci_sysfs_device_link,
+ PCI_SYSFS "devices/%04x:%02x:%02x.%x", dev->domain,
+ dev->bus, dev->slot, dev->function) < 0)
+ return -1;
+ return 0;
}
/*
return -1;
}
- return virAsprintf(wwn, "5" "%s%09llx", oui,
- (unsigned long long)virRandomBits(36));
+ if (virAsprintf(wwn, "5" "%s%09llx", oui,
+ (unsigned long long)virRandomBits(36)) < 0)
+ return -1;
+ return 0;
}
* Like glibc's vasprintf but makes sure *strp == NULL on failure, in which
* case the OOM error is reported too.
*
- * Returns -1 on failure (with OOM error reported), 0 on success.
+ * Returns -1 on failure (with OOM error reported), number of bytes printed
+ * on success.
*/
# define virVasprintf(strp, fmt, list) \
virVasprintfInternal(true, VIR_FROM_THIS, __FILE__, __FUNCTION__, \
*
* Like glibc's vasprintf but makes sure *strp == NULL on failure.
*
- * Returns -1 on failure, 0 on success.
+ * Returns -1 on failure, number of bytes printed on success.
*/
# define virVasprintfQuiet(strp, fmt, list) \
virVasprintfInternal(false, 0, NULL, NULL, 0, strp, fmt, list)
* Like glibc's_asprintf but makes sure *strp == NULL on failure, in which case
* the OOM error is reported too.
*
- * Returns -1 on failure (with OOM error reported), 0 on success.
+ * Returns -1 on failure (with OOM error reported), number of bytes printed
+ * on success.
*/
# define virAsprintf(strp, ...) \
*
* Like glibc's_asprintf but makes sure *strp == NULL on failure.
*
- * Returns -1 on failure, 0 on success.
+ * Returns -1 on failure, number of bytes printed on success.
*/
# define virAsprintfQuiet(strp, ...) \
int
vmwareConstructVmxPath(char *directoryName, char *name, char **vmxPath)
{
+ int ret;
+
if (directoryName != NULL)
- return virAsprintf(vmxPath, "%s/%s.vmx", directoryName, name);
- return virAsprintf(vmxPath, "%s.vmx", name);
+ ret = virAsprintf(vmxPath, "%s/%s.vmx", directoryName, name);
+ else
+ ret = virAsprintf(vmxPath, "%s.vmx", name);
+
+ if (ret < 0)
+ return -1;
+ return 0;
}
int
int
vmwareMakePath(char *srcDir, char *srcName, char *srcExt, char **outpath)
{
- return virAsprintf(outpath, "%s/%s.%s", srcDir, srcName, srcExt);
+ if (virAsprintf(outpath, "%s/%s.%s", srcDir, srcName, srcExt) < 0)
+ return -1;
+ return 0;
}
int
#define testError(...) \
do { \
char *str; \
- if (virAsprintfQuiet(&str, __VA_ARGS__) == 0) { \
+ if (virAsprintfQuiet(&str, __VA_ARGS__) >= 0) { \
fprintf(stderr, "%s", str); \
VIR_FREE(str); \
} \