8000 bpo-44946: Streamline operators and creation of ints for common case of single 'digit'. by markshannon · Pull Request #27832 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-44946: Streamline operators and creation of ints for common case of single 'digit'. #27832

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 17 commits into from
Aug 25, 2021
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
Don't overflow shift in PyLong_FromLong.
  • Loading branch information
markshannon committed Aug 23, 2021
commit 649c31180fbf72416cfe3d063ca592769e2cf049
5 changes: 3 additions & 2 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,9 @@ PyLong_FromLong(long ival)
if (!(abs_ival >> PyLong_SHIFT)) {
return _PyLong_FromMedium((sdigit)ival);
}
/* Must be at least two digits */
unsigned long t = abs_ival >> (PyLong_SHIFT *2);
/* Must be at least two digits.
* Do shift in two steps to avoid undefined behavior. */
unsigned long t = (abs_ival >> PyLong_SHIFT) >> PyLong_SHIFT;
Py_ssize_t ndigits = 2;
while (t) {
++ndigits;
Expand Down
0