diff --git a/cfg.mk b/cfg.mk index baaab710a674108f3db29dfffbc05a46ef349d28..c3d89a019d710a671d3fee5d46c128f33b81f8cc 100644 --- a/cfg.mk +++ b/cfg.mk @@ -1078,7 +1078,7 @@ exclude_file_name_regexp--sc_prohibit_sprintf = \ exclude_file_name_regexp--sc_prohibit_strncpy = ^src/util/virstring\.c$$ exclude_file_name_regexp--sc_prohibit_strtol = \ - ^(src/(util/virsexpr|(vbox|xen|xenxs)/.*)\.c)|(examples/domsuspend/suspend.c)$$ + ^(src/util/.*|examples/domsuspend/suspend)\.c$$ exclude_file_name_regexp--sc_prohibit_xmlGetProp = ^src/util/virxml\.c$$ diff --git a/src/util/virsexpr.c b/src/util/virsexpr.c index e2eb873fe85c51abab00423c455b0d0eedf26469..f5eb364e40b436981590cb5ec72be7be624689b0 100644 --- a/src/util/virsexpr.c +++ b/src/util/virsexpr.c @@ -566,7 +566,9 @@ sexpr_int(const struct sexpr *sexpr, const char *name) const char *value = sexpr_node(sexpr, name); if (value) { - return strtol(value, NULL, 0); + int val = 0; + virStrToLong_i(value, NULL, 0, &val); + return val; } return 0; } @@ -587,7 +589,9 @@ sexpr_float(const struct sexpr *sexpr, const char *name) const char *value = sexpr_node(sexpr, name); if (value) { - return strtod(value, NULL); + double val = 0; + virStrToDouble(value, NULL, &val); + return val; } return 0; } @@ -608,7 +612,9 @@ sexpr_u64(const struct sexpr *sexpr, const char *name) const char *value = sexpr_node(sexpr, name); if (value) { - return strtoll(value, NULL, 0); + unsigned long long val = 0; + virStrToLong_ull(value, NULL, 0, &val); + return val; } return 0; } diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index fa5020f084604111e26246afaba1c5f42a5b9916..e60a6726895030a7a1629c00ded486bbda82b0b3 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2344,8 +2344,8 @@ static void vboxHostDeviceGetXMLDesc(vboxGlobalData *data, virDomainDefPtr def, VBOX_UTF16_TO_UTF8(vendorIdUtf16, &vendorIdUtf8); VBOX_UTF16_TO_UTF8(productIdUtf16, &productIdUtf8); - vendorId = strtol(vendorIdUtf8, &endptr, 16); - productId = strtol(productIdUtf8, &endptr, 16); + virStrToLong_ui(vendorIdUtf8, &endptr, 16, &vendorId); + virStrToLong_ui(productIdUtf8, &endptr, 16, &productId); def->hostdevs[USBFilterCount]->source.subsys.u.usb.vendor = vendorId; def->hostdevs[USBFilterCount]->source.subsys.u.usb.product = productId; diff --git a/src/xen/block_stats.c b/src/xen/block_stats.c index ebbbd36aafb146ab01f7d9e785138ee90278ffb3..27e1019c5cdfd2df924a147311a46fc1dc942cd0 100644 --- a/src/xen/block_stats.c +++ b/src/xen/block_stats.c @@ -59,20 +59,6 @@ # define XENVBD_MAJOR 202 # endif -static int -xstrtoint64(char const *s, int base, int64_t *result) -{ - long long int lli; - char *p; - - errno = 0; - lli = strtoll(s, &p, base); - if (errno || !(*p == 0 || *p == '\n') || p == s || (int64_t) lli != lli) - return -1; - *result = lli; - return 0; -} - static int64_t read_stat(const char *path) { @@ -93,7 +79,7 @@ read_stat(const char *path) return -1; str[i] = '\0'; /* make sure the string is nul-terminated */ - if (xstrtoint64(str, 10, &r) == -1) + if (virStrToLong_ll(str, NULL, 10, (long long *) &r) < 0) return -1; return r; diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index b2797b69bedd1b4f5d7013cd60b39763f94bddb6..519a58f86ca214604d69ec96591f5e62936dbdc2 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -849,9 +849,7 @@ xenDaemonDomainLookupByName_ids(virConnectPtr xend, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("domain information incomplete, missing domid")); goto error; - } - ret = strtol(value, NULL, 0); - if ((ret == 0) && (value[0] != '0')) { + } else if (virStrToLong_i(value, NULL, 0, &ret) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("domain information incorrect domid not numeric")); ret = -1; @@ -874,22 +872,26 @@ xend_detect_config_version(virConnectPtr conn) struct sexpr *root; const char *value; xenUnifiedPrivatePtr priv = conn->privateData; + int ret = -1; root = sexpr_get(conn, "/xend/node/"); if (root == NULL) - return -1; + return ret; value = sexpr_node(root, "node/xend_config_format"); if (value) { - priv->xendConfigVersion = strtol(value, NULL, 10); + if (virStrToLong_i(value, NULL, 10, &priv->xendConfigVersion) < 0) + goto cleanup; } else { /* Xen prior to 3.0.3 did not have the xend_config_format field, and is implicitly version 1. */ priv->xendConfigVersion = XEND_CONFIG_VERSION_3_0_2; } + ret = 0; + cleanup: sexpr_free(root); - return 0; + return ret; } diff --git a/src/xen/xs_internal.c b/src/xen/xs_internal.c index 8702b1a563fb55efe786862647f66f57a7b6a14d..8ddcd7ebb88e1a5c85230974b9e0e5666598e28d 100644 --- a/src/xen/xs_internal.c +++ b/src/xen/xs_internal.c @@ -224,7 +224,7 @@ int xenStoreNumOfDomains(virConnectPtr conn) { unsigned int num; - char **idlist = NULL, *endptr; + char **idlist = NULL; size_t i; int ret = -1, realnum = 0; long id; @@ -233,8 +233,7 @@ xenStoreNumOfDomains(virConnectPtr conn) idlist = xs_directory(priv->xshandle, 0, "/local/domain", &num); if (idlist) { for (i = 0; i < num; i++) { - id = strtol(idlist[i], &endptr, 10); - if ((endptr == idlist[i]) || (*endptr != 0)) + if (virStrToLong_l(idlist[i], NULL, 10, &id) < 0) goto out; /* Sometimes xenstore has stale domain IDs, so filter @@ -266,7 +265,7 @@ xenStoreDoListDomains(virConnectPtr conn, int *ids, int maxids) { - char **idlist = NULL, *endptr; + char **idlist = NULL; unsigned int num; size_t i; int ret = -1; @@ -277,8 +276,7 @@ xenStoreDoListDomains(virConnectPtr conn, goto out; for (ret = 0, i = 0; (i < num) && (ret < maxids); i++) { - id = strtol(idlist[i], &endptr, 10); - if ((endptr == idlist[i]) || (*endptr != 0)) + if (virStrToLong_l(idlist[i], NULL, 10, &id) < 0) goto out; /* Sometimes xenstore has stale domain IDs, so filter @@ -337,10 +335,7 @@ xenStoreDomainGetVNCPort(virConnectPtr conn, int domid) tmp = virDomainDoStoreQuery(conn, domid, "console/vnc-port"); if (tmp != NULL) { - char *end; - ret = strtol(tmp, &end, 10); - if (ret == 0 && end == tmp) - ret = -1; + virStrToLong_i(tmp, NULL, 10, &ret); VIR_FREE(tmp); } return ret; diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 25a042da461b89586021fce9668f89381ac98ec1..7eb183ee564ee915b3477b3038441fb0393941cd 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -84,9 +84,7 @@ static int xenXMConfigGetULong(virConfPtr conf, if (val->type == VIR_CONF_LONG) { *value = val->l; } else if (val->type == VIR_CONF_STRING) { - char *ret; - *value = strtol(val->str, &ret, 10); - if (ret == val->str) { + if (virStrToLong_ul(val->str, NULL, 10, value) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("config value %s was malformed"), name); return -1; @@ -117,9 +115,7 @@ static int xenXMConfigGetULongLong(virConfPtr conf, if (val->type == VIR_CONF_LONG) { *value = val->l; } else if (val->type == VIR_CONF_STRING) { - char *ret; - *value = strtoll(val->str, &ret, 10); - if (ret == val->str) { + if (virStrToLong_ull(val->str, NULL, 10, value) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("config value %s was malformed"), name); return -1; @@ -1030,7 +1026,9 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (VIR_STRDUP(graphics->data.vnc.keymap, key + 7) < 0) goto cleanup; } else if (STRPREFIX(key, "vncdisplay=")) { - graphics->data.vnc.port = strtol(key+11, NULL, 10) + 5900; + virStrToLong_i(key + 11, NULL, 10, + &graphics->data.vnc.port); + graphics->data.vnc.port += 5900; } } else { if (STRPREFIX(key, "display=")) {