GitHub

@@ -1753,7 +1753,11 @@ pylong_int_to_decimal_string(PyObject *aa,

17531753

if (s == NULL) {

17541754

goto error;

17551755

}

1756-

assert(PyUnicode_Check(s));

1756+

if (!PyUnicode_Check(s)) {

1757+

PyErr_SetString(PyExc_TypeError,

1758+

"_pylong.int_to_decimal_string did not return a str");

1759+

goto error;

1760+

}

17571761

if (writer) {

17581762

Py_ssize_t size = PyUnicode_GET_LENGTH(s);

17591763

if (_PyUnicodeWriter_Prepare(writer, size, '9') == -1) {

@@ -2362,6 +2366,7 @@ pylong_int_from_string(const char *start, const char *end, PyLongObject **res)

23622366

}

23632367

PyObject *s = PyUnicode_FromStringAndSize(start, end-start);

23642368

if (s == NULL) {

2369+

Py_DECREF(mod);

23652370

goto error;

23662371

}

23672372

PyObject *result = PyObject_CallMethod(mod, "int_from_string", "O", s);

@@ -2371,14 +2376,15 @@ pylong_int_from_string(const char *start, const char *end, PyLongObject **res)

23712376

goto error;

23722377

}

23732378

if (!PyLong_Check(result)) {

2374-

PyErr_SetString(PyExc_TypeError, "an integer is required");

2379+

PyErr_SetString(PyExc_TypeError,

2380+

"_pylong.int_from_string did not return an int");

23752381

goto error;

23762382

}

23772383

*res = (PyLongObject *)result;

23782384

return 0;

23792385

error:

23802386

*res = NULL;

2381-

return 0;

2387+

return 0; // See the long_from_string_base() API comment.

23822388

}

23832389

#endif /* WITH_PYLONG_MODULE */

23842390

@@ -2617,7 +2623,8 @@ long_from_non_binary_base(const char *start, const char *end, Py_ssize_t digits,

26172623

* Return values:

26182624

*

26192625

* - Returns -1 on syntax error (exception needs to be set, *res is untouched)

2620-

* - Returns 0 and sets *res to NULL for MemoryError/OverflowError.

2626+

* - Returns 0 and sets *res to NULL for MemoryError, OverflowError, or

2627+

* _pylong.int_from_string() errors.

26212628

* - Returns 0 and sets *res to an unsigned, unnormalized PyLong (success!).

26222629

*

26232630

* Afterwards *str is set to point to the first non-digit (which may be *str!).

Read the original on github.com ↗