]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Raise ValueError on empty string passed into atoi(), atol(), atof().
authorGuido van Rossum <guido@python.org>
Wed, 21 Aug 1996 20:02:25 +0000 (20:02 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 21 Aug 1996 20:02:25 +0000 (20:02 +0000)
Modules/stropmodule.c

index ef943a431146ac6d26f08df3240e8f6a61430371..0540a9d820a98feef287249ebc69c3e66baa9cbc 100644 (file)
@@ -537,6 +537,10 @@ strop_atoi(self, args)
        }
        else if (!getargs(args, "s", &s))
                return NULL;
+       if (s[0] == '\0') {
+               err_setstr(ValueError, "empty string for atoi()");
+               return NULL;
+       }
        errno = 0;
        if (base == 0 && s[0] == '0')
                x = (long) mystrtoul(s, &end, base);
@@ -573,6 +577,10 @@ strop_atol(self, args)
        }
        else if (!getargs(args, "s", &s))
                return NULL;
+       if (s[0] == '\0') {
+               err_setstr(ValueError, "empty string for atol()");
+               return NULL;
+       }
        x = long_escan(s, &end, base);
        if (x == NULL)
                return NULL;
@@ -598,6 +606,10 @@ strop_atof(self, args)
 
        if (!getargs(args, "s", &s))
                return NULL;
+       if (s[0] == '\0') {
+               err_setstr(ValueError, "empty string for atof()");
+               return NULL;
+       }
        errno = 0;
        x = strtod(s, &end);
        if (*end != '\0') {