]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.13] gh-71810: Fix corner case (length==0) for int.to_bytes() (GH-138739) (#138783)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 11 Sep 2025 10:53:27 +0000 (12:53 +0200)
committerGitHub <noreply@github.com>
Thu, 11 Sep 2025 10:53:27 +0000 (10:53 +0000)
commit7195d7f3d4c79f3711ede2e504c19bedc39aa3ad
tree0d98c03cb6a79b7b87f6b90f6c4cb10e8a92bf66
parent72b28cad917c5ef3b0d26d81bbe9ed3a151f4ad3
[3.13] gh-71810: Fix corner case (length==0) for int.to_bytes() (GH-138739) (#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 011179a79a0d7b93ce074b25b0819e96b6dd3315)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/test_long.py
Misc/NEWS.d/next/Core_and_Builtins/2025-09-10-14-53-59.gh-issue-71810.ppf0J-.rst [new file with mode: 0644]
Objects/longobject.c