summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-09-11 23:30:42 +0000
committerGuido van Rossum <guido@python.org>1996-09-11 23:30:42 +0000
commit8af6f0d2707df0550b4a9a477f88cb756450960e (patch)
treeae689e003b5875d0f54058e8a662007ba8da6cd0
parent69ec649f7fffd425a2a8b639ee3c846e0108052f (diff)
downloadcpython-8af6f0d2707df0550b4a9a477f88cb756450960e.tar.gz
Add text of argument to errors for atoi(), atol(), atof().
-rw-r--r--Modules/stropmodule.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/Modules/stropmodule.c b/Modules/stropmodule.c
index 0540a9d820..a70df8cde4 100644
--- a/Modules/stropmodule.c
+++ b/Modules/stropmodule.c
@@ -526,6 +526,7 @@ strop_atoi(self, args)
char *s, *end;
int base = 10;
long x;
+ char buffer[256]; /* For errors */
if (args != NULL && is_tupleobject(args)) {
if (!getargs(args, "(si)", &s, &base))
@@ -537,6 +538,8 @@ strop_atoi(self, args)
}
else if (!getargs(args, "s", &s))
return NULL;
+ while (*s && isspace(Py_CHARMASK(*s)))
+ s++;
if (s[0] == '\0') {
err_setstr(ValueError, "empty string for atoi()");
return NULL;
@@ -546,12 +549,16 @@ strop_atoi(self, args)
x = (long) mystrtoul(s, &end, base);
else
x = mystrtol(s, &end, base);
+ while (*end && isspace(Py_CHARMASK(*end)))
+ end++;
if (*end != '\0') {
- err_setstr(ValueError, "invalid literal for atoi()");
+ sprintf(buffer, "invalid literal for atoi(): %.200s", s);
+ err_setstr(ValueError, buffer);
return NULL;
}
else if (errno != 0) {
- err_setstr(OverflowError, "atoi() literal too large");
+ sprintf(buffer, "atoi() literal too large: %.200s", s);
+ err_setstr(ValueError, buffer);
return NULL;
}
return newintobject(x);
@@ -566,6 +573,7 @@ strop_atol(self, args)
char *s, *end;
int base = 10;
object *x;
+ char buffer[256]; /* For errors */
if (args != NULL && is_tupleobject(args)) {
if (!getargs(args, "(si)", &s, &base))
@@ -577,6 +585,8 @@ strop_atol(self, args)
}
else if (!getargs(args, "s", &s))
return NULL;
+ while (*s && isspace(Py_CHARMASK(*s)))
+ s++;
if (s[0] == '\0') {
err_setstr(ValueError, "empty string for atol()");
return NULL;
@@ -586,8 +596,11 @@ strop_atol(self, args)
return NULL;
if (base == 0 && (*end == 'l' || *end == 'L'))
end++;
+ while (*end && isspace(Py_CHARMASK(*end)))
+ end++;
if (*end != '\0') {
- err_setstr(ValueError, "invalid literal for atol()");
+ sprintf(buffer, "invalid literal for atol(): %.200s", s);
+ err_setstr(ValueError, buffer);
DECREF(x);
return NULL;
}
@@ -603,21 +616,28 @@ strop_atof(self, args)
extern double strtod PROTO((const char *, char **));
char *s, *end;
double x;
+ char buffer[256]; /* For errors */
if (!getargs(args, "s", &s))
return NULL;
+ while (*s && isspace(Py_CHARMASK(*s)))
+ s++;
if (s[0] == '\0') {
err_setstr(ValueError, "empty string for atof()");
return NULL;
}
errno = 0;
x = strtod(s, &end);
+ while (*end && isspace(Py_CHARMASK(*end)))
+ end++;
if (*end != '\0') {
- err_setstr(ValueError, "invalid literal for atof()");
+ sprintf(buffer, "invalid literal for atof(): %.200s", s);
+ err_setstr(ValueError, buffer);
return NULL;
}
else if (errno != 0) {
- err_setstr(OverflowError, "atof() literal too large");
+ sprintf(buffer, "atof() literal too large: %.200s", s);
+ err_setstr(ValueError, buffer);
return NULL;
}
return newfloatobject(x);