提交 50281605 编写于 作者: M Michal Privoznik

Kill last strto{l,ll,d} scouts

There's no need to use it since we have this shiny functions
that even checks for conversion and overflow errors.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 7c10a774
...@@ -1078,7 +1078,7 @@ exclude_file_name_regexp--sc_prohibit_sprintf = \ ...@@ -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_strncpy = ^src/util/virstring\.c$$
exclude_file_name_regexp--sc_prohibit_strtol = \ 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$$ exclude_file_name_regexp--sc_prohibit_xmlGetProp = ^src/util/virxml\.c$$
......
...@@ -566,7 +566,9 @@ sexpr_int(const struct sexpr *sexpr, const char *name) ...@@ -566,7 +566,9 @@ sexpr_int(const struct sexpr *sexpr, const char *name)
const char *value = sexpr_node(sexpr, name); const char *value = sexpr_node(sexpr, name);
if (value) { if (value) {
return strtol(value, NULL, 0); int val = 0;
virStrToLong_i(value, NULL, 0, &val);
return val;
} }
return 0; return 0;
} }
...@@ -587,7 +589,9 @@ sexpr_float(const struct sexpr *sexpr, const char *name) ...@@ -587,7 +589,9 @@ sexpr_float(const struct sexpr *sexpr, const char *name)
const char *value = sexpr_node(sexpr, name); const char *value = sexpr_node(sexpr, name);
if (value) { if (value) {
return strtod(value, NULL); double val = 0;
virStrToDouble(value, NULL, &val);
return val;
} }
return 0; return 0;
} }
...@@ -608,7 +612,9 @@ sexpr_u64(const struct sexpr *sexpr, const char *name) ...@@ -608,7 +612,9 @@ sexpr_u64(const struct sexpr *sexpr, const char *name)
const char *value = sexpr_node(sexpr, name); const char *value = sexpr_node(sexpr, name);
if (value) { if (value) {
return strtoll(value, NULL, 0); unsigned long long val = 0;
virStrToLong_ull(value, NULL, 0, &val);
return val;
} }
return 0; return 0;
} }
...@@ -2344,8 +2344,8 @@ static void vboxHostDeviceGetXMLDesc(vboxGlobalData *data, virDomainDefPtr def, ...@@ -2344,8 +2344,8 @@ static void vboxHostDeviceGetXMLDesc(vboxGlobalData *data, virDomainDefPtr def,
VBOX_UTF16_TO_UTF8(vendorIdUtf16, &vendorIdUtf8); VBOX_UTF16_TO_UTF8(vendorIdUtf16, &vendorIdUtf8);
VBOX_UTF16_TO_UTF8(productIdUtf16, &productIdUtf8); VBOX_UTF16_TO_UTF8(productIdUtf16, &productIdUtf8);
vendorId = strtol(vendorIdUtf8, &endptr, 16); virStrToLong_ui(vendorIdUtf8, &endptr, 16, &vendorId);
productId = strtol(productIdUtf8, &endptr, 16); virStrToLong_ui(productIdUtf8, &endptr, 16, &productId);
def->hostdevs[USBFilterCount]->source.subsys.u.usb.vendor = vendorId; def->hostdevs[USBFilterCount]->source.subsys.u.usb.vendor = vendorId;
def->hostdevs[USBFilterCount]->source.subsys.u.usb.product = productId; def->hostdevs[USBFilterCount]->source.subsys.u.usb.product = productId;
......
...@@ -59,20 +59,6 @@ ...@@ -59,20 +59,6 @@
# define XENVBD_MAJOR 202 # define XENVBD_MAJOR 202
# endif # 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 static int64_t
read_stat(const char *path) read_stat(const char *path)
{ {
...@@ -93,7 +79,7 @@ read_stat(const char *path) ...@@ -93,7 +79,7 @@ read_stat(const char *path)
return -1; return -1;
str[i] = '\0'; /* make sure the string is nul-terminated */ 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 -1;
return r; return r;
......
...@@ -849,9 +849,7 @@ xenDaemonDomainLookupByName_ids(virConnectPtr xend, ...@@ -849,9 +849,7 @@ xenDaemonDomainLookupByName_ids(virConnectPtr xend,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("domain information incomplete, missing domid")); "%s", _("domain information incomplete, missing domid"));
goto error; goto error;
} } else if (virStrToLong_i(value, NULL, 0, &ret) < 0) {
ret = strtol(value, NULL, 0);
if ((ret == 0) && (value[0] != '0')) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("domain information incorrect domid not numeric")); "%s", _("domain information incorrect domid not numeric"));
ret = -1; ret = -1;
...@@ -874,22 +872,26 @@ xend_detect_config_version(virConnectPtr conn) ...@@ -874,22 +872,26 @@ xend_detect_config_version(virConnectPtr conn)
struct sexpr *root; struct sexpr *root;
const char *value; const char *value;
xenUnifiedPrivatePtr priv = conn->privateData; xenUnifiedPrivatePtr priv = conn->privateData;
int ret = -1;
root = sexpr_get(conn, "/xend/node/"); root = sexpr_get(conn, "/xend/node/");
if (root == NULL) if (root == NULL)
return -1; return ret;
value = sexpr_node(root, "node/xend_config_format"); value = sexpr_node(root, "node/xend_config_format");
if (value) { if (value) {
priv->xendConfigVersion = strtol(value, NULL, 10); if (virStrToLong_i(value, NULL, 10, &priv->xendConfigVersion) < 0)
goto cleanup;
} else { } else {
/* Xen prior to 3.0.3 did not have the xend_config_format /* Xen prior to 3.0.3 did not have the xend_config_format
field, and is implicitly version 1. */ field, and is implicitly version 1. */
priv->xendConfigVersion = XEND_CONFIG_VERSION_3_0_2; priv->xendConfigVersion = XEND_CONFIG_VERSION_3_0_2;
} }
ret = 0;
cleanup:
sexpr_free(root); sexpr_free(root);
return 0; return ret;
} }
......
...@@ -224,7 +224,7 @@ int ...@@ -224,7 +224,7 @@ int
xenStoreNumOfDomains(virConnectPtr conn) xenStoreNumOfDomains(virConnectPtr conn)
{ {
unsigned int num; unsigned int num;
char **idlist = NULL, *endptr; char **idlist = NULL;
size_t i; size_t i;
int ret = -1, realnum = 0; int ret = -1, realnum = 0;
long id; long id;
...@@ -233,8 +233,7 @@ xenStoreNumOfDomains(virConnectPtr conn) ...@@ -233,8 +233,7 @@ xenStoreNumOfDomains(virConnectPtr conn)
idlist = xs_directory(priv->xshandle, 0, "/local/domain", &num); idlist = xs_directory(priv->xshandle, 0, "/local/domain", &num);
if (idlist) { if (idlist) {
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
id = strtol(idlist[i], &endptr, 10); if (virStrToLong_l(idlist[i], NULL, 10, &id) < 0)
if ((endptr == idlist[i]) || (*endptr != 0))
goto out; goto out;
/* Sometimes xenstore has stale domain IDs, so filter /* Sometimes xenstore has stale domain IDs, so filter
...@@ -266,7 +265,7 @@ xenStoreDoListDomains(virConnectPtr conn, ...@@ -266,7 +265,7 @@ xenStoreDoListDomains(virConnectPtr conn,
int *ids, int *ids,
int maxids) int maxids)
{ {
char **idlist = NULL, *endptr; char **idlist = NULL;
unsigned int num; unsigned int num;
size_t i; size_t i;
int ret = -1; int ret = -1;
...@@ -277,8 +276,7 @@ xenStoreDoListDomains(virConnectPtr conn, ...@@ -277,8 +276,7 @@ xenStoreDoListDomains(virConnectPtr conn,
goto out; goto out;
for (ret = 0, i = 0; (i < num) && (ret < maxids); i++) { for (ret = 0, i = 0; (i < num) && (ret < maxids); i++) {
id = strtol(idlist[i], &endptr, 10); if (virStrToLong_l(idlist[i], NULL, 10, &id) < 0)
if ((endptr == idlist[i]) || (*endptr != 0))
goto out; goto out;
/* Sometimes xenstore has stale domain IDs, so filter /* Sometimes xenstore has stale domain IDs, so filter
...@@ -337,10 +335,7 @@ xenStoreDomainGetVNCPort(virConnectPtr conn, int domid) ...@@ -337,10 +335,7 @@ xenStoreDomainGetVNCPort(virConnectPtr conn, int domid)
tmp = virDomainDoStoreQuery(conn, domid, "console/vnc-port"); tmp = virDomainDoStoreQuery(conn, domid, "console/vnc-port");
if (tmp != NULL) { if (tmp != NULL) {
char *end; virStrToLong_i(tmp, NULL, 10, &ret);
ret = strtol(tmp, &end, 10);
if (ret == 0 && end == tmp)
ret = -1;
VIR_FREE(tmp); VIR_FREE(tmp);
} }
return ret; return ret;
......
...@@ -84,9 +84,7 @@ static int xenXMConfigGetULong(virConfPtr conf, ...@@ -84,9 +84,7 @@ static int xenXMConfigGetULong(virConfPtr conf,
if (val->type == VIR_CONF_LONG) { if (val->type == VIR_CONF_LONG) {
*value = val->l; *value = val->l;
} else if (val->type == VIR_CONF_STRING) { } else if (val->type == VIR_CONF_STRING) {
char *ret; if (virStrToLong_ul(val->str, NULL, 10, value) < 0) {
*value = strtol(val->str, &ret, 10);
if (ret == val->str) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("config value %s was malformed"), name); _("config value %s was malformed"), name);
return -1; return -1;
...@@ -117,9 +115,7 @@ static int xenXMConfigGetULongLong(virConfPtr conf, ...@@ -117,9 +115,7 @@ static int xenXMConfigGetULongLong(virConfPtr conf,
if (val->type == VIR_CONF_LONG) { if (val->type == VIR_CONF_LONG) {
*value = val->l; *value = val->l;
} else if (val->type == VIR_CONF_STRING) { } else if (val->type == VIR_CONF_STRING) {
char *ret; if (virStrToLong_ull(val->str, NULL, 10, value) < 0) {
*value = strtoll(val->str, &ret, 10);
if (ret == val->str) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("config value %s was malformed"), name); _("config value %s was malformed"), name);
return -1; return -1;
...@@ -1030,7 +1026,9 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -1030,7 +1026,9 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
if (VIR_STRDUP(graphics->data.vnc.keymap, key + 7) < 0) if (VIR_STRDUP(graphics->data.vnc.keymap, key + 7) < 0)
goto cleanup; goto cleanup;
} else if (STRPREFIX(key, "vncdisplay=")) { } 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 { } else {
if (STRPREFIX(key, "display=")) { if (STRPREFIX(key, "display=")) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册