diff options
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r-- | Objects/floatobject.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 5af2678..064ba2e 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -150,11 +150,18 @@ float_from_string_inner(const char *s, Py_ssize_t len, void *obj) double x; const char *end; const char *last = s + len; - /* strip space */ + /* strip leading whitespace */ while (s < last && Py_ISSPACE(*s)) { s++; } + if (s == last) { + PyErr_Format(PyExc_ValueError, + "could not convert string to float: " + "%R", obj); + return NULL; + } + /* strip trailing whitespace */ while (s < last - 1 && Py_ISSPACE(last[-1])) { last--; } |