mirror of
https://github.com/python/cpython.git
synced 2025-11-03 11:23:31 +00:00
Raise ValueError on empty string passed into atoi(), atol(), atof().
This commit is contained in:
parent
d0f11dec30
commit
171191efb2
1 changed files with 12 additions and 0 deletions
|
|
@ -537,6 +537,10 @@ strop_atoi(self, args)
|
||||||
}
|
}
|
||||||
else if (!getargs(args, "s", &s))
|
else if (!getargs(args, "s", &s))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (s[0] == '\0') {
|
||||||
|
err_setstr(ValueError, "empty string for atoi()");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if (base == 0 && s[0] == '0')
|
if (base == 0 && s[0] == '0')
|
||||||
x = (long) mystrtoul(s, &end, base);
|
x = (long) mystrtoul(s, &end, base);
|
||||||
|
|
@ -573,6 +577,10 @@ strop_atol(self, args)
|
||||||
}
|
}
|
||||||
else if (!getargs(args, "s", &s))
|
else if (!getargs(args, "s", &s))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (s[0] == '\0') {
|
||||||
|
err_setstr(ValueError, "empty string for atol()");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
x = long_escan(s, &end, base);
|
x = long_escan(s, &end, base);
|
||||||
if (x == NULL)
|
if (x == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -598,6 +606,10 @@ strop_atof(self, args)
|
||||||
|
|
||||||
if (!getargs(args, "s", &s))
|
if (!getargs(args, "s", &s))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (s[0] == '\0') {
|
||||||
|
err_setstr(ValueError, "empty string for atof()");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
errno = 0;
|
errno = 0;
|
||||||
x = strtod(s, &end);
|
x = strtod(s, &end);
|
||||||
if (*end != '\0') {
|
if (*end != '\0') {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue