8000 gh-95778: Add pre-check for int-to-str conversion by mdickinson · Pull Request #96537 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-95778: Add pre-check for int-to-str conversion #96537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Sep 4, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update comment to suggest reading the PR for detail
  • Loading branch information
gpshead committed Sep 4, 2022
commit 730915df6b236d1937466c724cc53c79009ef532
7 changes: 5 additions & 2 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1759,8 +1759,11 @@ long_to_decimal_string_internal(PyObject *aa,
size_a = Py_ABS(Py_SIZE(a));
negative = Py_SIZE(a) < 0;

/* quick and dirty pre-check for overflowing the digit limit,
based on the inequality 10/3 >= log2(10) */
/* quick and dirty pre-check for overflowing the decimal digit limit,
based on the inequality 10/3 >= log2(10)

explanation in https://github.com/python/cpython/pull/96537
*/
if (size_a >= 10 * _PY_LONG_MAX_STR_DIGITS_THRESHOLD
/ (3 * PyLong_SHIFT) + 2) {
PyInterpreterState *interp = _PyInterpreterState_GET();
Expand Down
0