mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 19:20:22 +01:00
py: Fix handling of negative numbers in struct.pack of q/Q.
This commit is contained in:
4
py/mpz.c
4
py/mpz.c
@@ -1441,8 +1441,8 @@ void mpz_as_bytes(const mpz_t *z, bool big_endian, mp_uint_t len, byte *buf) {
|
||||
for (; bits >= 8; bits -= 8, d >>= 8) {
|
||||
mpz_dig_t val = d;
|
||||
if (z->neg) {
|
||||
d = (~d & 0xff) + carry;
|
||||
carry = d >> 8;
|
||||
val = (~val & 0xff) + carry;
|
||||
carry = val >> 8;
|
||||
}
|
||||
if (big_endian) {
|
||||
*--b = val;
|
||||
|
||||
Reference in New Issue
Block a user