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: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2014-07-18 09:46:39 +02:00
parent 7c10a77422
commit 5028160523
7 changed files with 31 additions and 44 deletions

2
cfg.mk
View File

@ -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$$

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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=")) {