mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
maint: remove redundant tests after virStrToLong
virStrToLong* guarantees (via strtol) that the end pointer will be set to the point at which parsing stopped (even on failure, this point is the start of the input string). * src/esx/esx_driver.c (esxGetVersion): Remove pointless conditional. * src/qemu/qemu_conf.c (qemuParseCommandLinePCI) (qemuParseCommandLineUSB, qemuParseCommandLineSmp): Likewise. * src/qemu/qemu_monitor_text.c (qemuMonitorTextGetMigrationStatus): Likewise.
This commit is contained in:
parent
8d773c0f4f
commit
9d6614df86
@ -690,13 +690,11 @@ esxGetVersion(virConnectPtr conn, unsigned long *version)
|
|||||||
temp = (char *)priv->host->service->about->version;
|
temp = (char *)priv->host->service->about->version;
|
||||||
|
|
||||||
/* Expecting 'major.minor.release' format */
|
/* Expecting 'major.minor.release' format */
|
||||||
if (virStrToLong_ui(temp, &temp, 10, &major) < 0 || temp == NULL ||
|
if (virStrToLong_ui(temp, &temp, 10, &major) < 0 || *temp != '.') {
|
||||||
*temp != '.') {
|
|
||||||
goto failure;
|
goto failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virStrToLong_ui(temp + 1, &temp, 10, &minor) < 0 || temp == NULL ||
|
if (virStrToLong_ui(temp + 1, &temp, 10, &minor) < 0 || *temp != '.') {
|
||||||
*temp != '.') {
|
|
||||||
goto failure;
|
goto failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5217,14 +5217,14 @@ qemuParseCommandLinePCI(const char *val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
start = val + strlen("host=");
|
start = val + strlen("host=");
|
||||||
if (virStrToLong_i(start, &end, 16, &bus) < 0 || !end || *end != ':') {
|
if (virStrToLong_i(start, &end, 16, &bus) < 0 || *end != ':') {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("cannot extract PCI device bus '%s'"), val);
|
_("cannot extract PCI device bus '%s'"), val);
|
||||||
VIR_FREE(def);
|
VIR_FREE(def);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
start = end + 1;
|
start = end + 1;
|
||||||
if (virStrToLong_i(start, &end, 16, &slot) < 0 || !end || *end != '.') {
|
if (virStrToLong_i(start, &end, 16, &slot) < 0 || *end != '.') {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("cannot extract PCI device slot '%s'"), val);
|
_("cannot extract PCI device slot '%s'"), val);
|
||||||
VIR_FREE(def);
|
VIR_FREE(def);
|
||||||
@ -5275,7 +5275,7 @@ qemuParseCommandLineUSB(const char *val)
|
|||||||
|
|
||||||
start = val + strlen("host:");
|
start = val + strlen("host:");
|
||||||
if (strchr(start, ':')) {
|
if (strchr(start, ':')) {
|
||||||
if (virStrToLong_i(start, &end, 16, &first) < 0 || !end || *end != ':') {
|
if (virStrToLong_i(start, &end, 16, &first) < 0 || *end != ':') {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("cannot extract USB device vendor '%s'"), val);
|
_("cannot extract USB device vendor '%s'"), val);
|
||||||
VIR_FREE(def);
|
VIR_FREE(def);
|
||||||
@ -5289,7 +5289,7 @@ qemuParseCommandLineUSB(const char *val)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (virStrToLong_i(start, &end, 10, &first) < 0 || !end || *end != '.') {
|
if (virStrToLong_i(start, &end, 10, &first) < 0 || *end != '.') {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("cannot extract USB device bus '%s'"), val);
|
_("cannot extract USB device bus '%s'"), val);
|
||||||
VIR_FREE(def);
|
VIR_FREE(def);
|
||||||
@ -5573,13 +5573,11 @@ qemuParseCommandLineSmp(virDomainDefPtr dom,
|
|||||||
for (i = 0; i < nkws; i++) {
|
for (i = 0; i < nkws; i++) {
|
||||||
if (vals[i] == NULL) {
|
if (vals[i] == NULL) {
|
||||||
if (i > 0 ||
|
if (i > 0 ||
|
||||||
virStrToLong_i(kws[i], &end, 10, &n) < 0 ||
|
virStrToLong_i(kws[i], &end, 10, &n) < 0 || *end != '\0')
|
||||||
!end || *end != '\0')
|
|
||||||
goto syntax;
|
goto syntax;
|
||||||
dom->vcpus = n;
|
dom->vcpus = n;
|
||||||
} else {
|
} else {
|
||||||
if (virStrToLong_i(vals[i], &end, 10, &n) < 0 ||
|
if (virStrToLong_i(vals[i], &end, 10, &n) < 0 || *end != '\0')
|
||||||
!end || *end != '\0')
|
|
||||||
goto syntax;
|
goto syntax;
|
||||||
if (STREQ(kws[i], "sockets"))
|
if (STREQ(kws[i], "sockets"))
|
||||||
sockets = n;
|
sockets = n;
|
||||||
|
@ -1075,7 +1075,7 @@ int qemuMonitorTextGetMigrationStatus(qemuMonitorPtr mon,
|
|||||||
goto done;
|
goto done;
|
||||||
tmp += strlen(MIGRATION_TRANSFER_PREFIX);
|
tmp += strlen(MIGRATION_TRANSFER_PREFIX);
|
||||||
|
|
||||||
if (virStrToLong_ull(tmp, &end, 10, transferred) < 0 || !end) {
|
if (virStrToLong_ull(tmp, &end, 10, transferred) < 0) {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("cannot parse migration data transferred statistic %s"), tmp);
|
_("cannot parse migration data transferred statistic %s"), tmp);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1087,7 +1087,7 @@ int qemuMonitorTextGetMigrationStatus(qemuMonitorPtr mon,
|
|||||||
goto done;
|
goto done;
|
||||||
tmp += strlen(MIGRATION_REMAINING_PREFIX);
|
tmp += strlen(MIGRATION_REMAINING_PREFIX);
|
||||||
|
|
||||||
if (virStrToLong_ull(tmp, &end, 10, remaining) < 0 || !end) {
|
if (virStrToLong_ull(tmp, &end, 10, remaining) < 0) {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("cannot parse migration data remaining statistic %s"), tmp);
|
_("cannot parse migration data remaining statistic %s"), tmp);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1098,7 +1098,7 @@ int qemuMonitorTextGetMigrationStatus(qemuMonitorPtr mon,
|
|||||||
goto done;
|
goto done;
|
||||||
tmp += strlen(MIGRATION_TOTAL_PREFIX);
|
tmp += strlen(MIGRATION_TOTAL_PREFIX);
|
||||||
|
|
||||||
if (virStrToLong_ull(tmp, &end, 10, total) < 0 || !end) {
|
if (virStrToLong_ull(tmp, &end, 10, total) < 0) {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("cannot parse migration data total statistic %s"), tmp);
|
_("cannot parse migration data total statistic %s"), tmp);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user