| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
```pycon
>>> (0).to_bytes(0, 'big', signed=True)
b''
>>> (-1).to_bytes(0, 'big', signed=True) # was b''
Traceback (most recent call last):
File "<python-input-0>", line 1, in <module>
(-1).to_bytes(0, 'big', signed=True)
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
OverflowError: int too big to convert
```
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
|
@serhiy-storchaka: I would suggest to backport this change to Python 3.13 and 3.14. What do you think? |
Sorry, something went wrong.
There was a problem hiding this comment.
It seems there are no enough tests for signed=True. Please add also tests for (128).to_bytes(0, 'big', signed=True) and (-129).to_bytes(0, 'big', signed=True).
Sorry, something went wrong.
|
Disclaimer: I was thinking about (0).to_bytes(0, 'big', signed=True) too, but that means rejecting also int.from_bytes(b"", ..., signed=True). That case looks for me as a special case, that aren't special enough to warrant compatibility break. |
Sorry, something went wrong.
|
Or better add several tests for extreme values and values just above the limit for all combination of signedness and n=0, 1, 2. |
Sorry, something went wrong.
Done. There are such tests, but rather for "automatic" value for length parameter (determined by result): Line 1262 in 1ce0553
It seems to be a big refactoring of tests. Maybe it does make sense as a separate pr? |
Sorry, something went wrong.
There was a problem hiding this comment.
I would add much more tests. Anyway, LGTM. 👍
Sorry, something went wrong.
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
Thanks @skirpichev for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
Sorry, something went wrong.
…nGH-138739) ```pycon >>> (0).to_bytes(0, 'big', signed=True) b'' >>> (-1).to_bytes(0, 'big', signed=True) # was b'' Traceback (most recent call last): File "<python-input-0>", line 1, in <module> (-1).to_bytes(0, 'big', signed=True) ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^ OverflowError: int too big to convert ``` (cherry picked from commit 011179a) Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…nGH-138739) ```pycon >>> (0).to_bytes(0, 'big', signed=True) b'' >>> (-1).to_bytes(0, 'big', signed=True) # was b'' Traceback (most recent call last): File "<python-input-0>", line 1, in <module> (-1).to_bytes(0, 'big', signed=True) ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^ OverflowError: int too big to convert ``` (cherry picked from commit 011179a) Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
GH-138782 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
|
GH-138783 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
|
Merged, thank you. |
Sorry, something went wrong.
…38739) (#138783) gh-71810: Fix corner case (length==0) for int.to_bytes() (GH-138739) ```pycon >>> (0).to_bytes(0, 'big', signed=True) b'' >>> (-1).to_bytes(0, 'big', signed=True) # was b'' Traceback (most recent call last): File "<python-input-0>", line 1, in <module> (-1).to_bytes(0, 'big', signed=True) ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^ OverflowError: int too big to convert ``` (cherry picked from commit 011179a) Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
| p += pincr; | ||
| } | ||
| else if (j == n && n > 0 && is_signed) { | ||
| else if (j == n && is_signed) { |
There was a problem hiding this comment.
This change introduced an undefined behavior: unsigned char msb = *(p - pincr); read is out of the bounds if n == 0. I wrote #138873 to fix it.
Sorry, something went wrong.
There was a problem hiding this comment.
Oh, sorry. Thanks!
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.