mirror of
https://github.com/python/cpython.git
synced 2025-12-09 02:35:14 +00:00
Change the error reporting when an invalid string is encountered to avoid
reporting s'x' as the input (which is a lie).
This commit is contained in:
parent
ae211f9abf
commit
2523621693
1 changed files with 9 additions and 18 deletions
|
|
@ -1689,7 +1689,7 @@ PyLong_FromString(char *str, char **pend, int base)
|
||||||
int sign = 1, error_if_nonzero = 0;
|
int sign = 1, error_if_nonzero = 0;
|
||||||
char *start, *orig_str = str;
|
char *start, *orig_str = str;
|
||||||
PyLongObject *z = NULL;
|
PyLongObject *z = NULL;
|
||||||
PyObject *strobj, *strrepr;
|
PyObject *strobj;
|
||||||
Py_ssize_t slen;
|
Py_ssize_t slen;
|
||||||
|
|
||||||
if ((base != 0 && base < 2) || base > 36) {
|
if ((base != 0 && base < 2) || base > 36) {
|
||||||
|
|
@ -1956,17 +1956,13 @@ digit beyond the first.
|
||||||
onError:
|
onError:
|
||||||
Py_XDECREF(z);
|
Py_XDECREF(z);
|
||||||
slen = strlen(orig_str) < 200 ? strlen(orig_str) : 200;
|
slen = strlen(orig_str) < 200 ? strlen(orig_str) : 200;
|
||||||
strobj = PyString_FromStringAndSize(orig_str, slen);
|
strobj = PyUnicode_FromStringAndSize(orig_str, slen);
|
||||||
if (strobj == NULL)
|
if (strobj == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
strrepr = PyObject_ReprStr8(strobj);
|
|
||||||
Py_DECREF(strobj);
|
|
||||||
if (strrepr == NULL)
|
|
||||||
return NULL;
|
|
||||||
PyErr_Format(PyExc_ValueError,
|
PyErr_Format(PyExc_ValueError,
|
||||||
"invalid literal for int() with base %d: %s",
|
"invalid literal for int() with base %d: %R",
|
||||||
base, PyString_AS_STRING(strrepr));
|
base, strobj);
|
||||||
Py_DECREF(strrepr);
|
Py_DECREF(strobj);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3533,16 +3529,11 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
size = PyString_GET_SIZE(x);
|
size = PyString_GET_SIZE(x);
|
||||||
}
|
}
|
||||||
if (strlen(string) != size) {
|
if (strlen(string) != size) {
|
||||||
/* create a repr() of the input string,
|
/* We only see this if there's a null byte in x,
|
||||||
* just like PyLong_FromString does. */
|
x is a str8 or a bytes, *and* a base is given. */
|
||||||
PyObject *srepr;
|
|
||||||
srepr = PyObject_ReprStr8(x);
|
|
||||||
if (srepr == NULL)
|
|
||||||
return NULL;
|
|
||||||
PyErr_Format(PyExc_ValueError,
|
PyErr_Format(PyExc_ValueError,
|
||||||
"invalid literal for int() with base %d: %s",
|
"invalid literal for int() with base %d: %R",
|
||||||
base, PyString_AS_STRING(srepr));
|
base, x);
|
||||||
Py_DECREF(srepr);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return PyLong_FromString(string, NULL, base);
|
return PyLong_FromString(string, NULL, base);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue