diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2022-08-10 18:25:39 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-10 18:25:39 (GMT) |
commit | 97e9cfa75a80b54a0630b7371f35e368a12749d1 (patch) | |
tree | 75e148bc8a55cd77ddc9cf81175079c3bf52d186 /Objects | |
parent | 37c0f9ccc06750a7e22f5c176df39373f7aca526 (diff) | |
download | cpython-97e9cfa75a80b54a0630b7371f35e368a12749d1.zip cpython-97e9cfa75a80b54a0630b7371f35e368a12749d1.tar.gz cpython-97e9cfa75a80b54a0630b7371f35e368a12749d1.tar.bz2 |
gh-95605: Fix `float(s)` error message when `s` contains only whitespace (GH-95665)
This PR fixes the error message from float(s) in the case where s contains only whitespace.
Diffstat (limited to 'Objects')
-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 4b1b24f..c435357 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -162,11 +162,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--; } |