Skip to content

Commit b9e7ed4

Browse files
committed
py: Oops, fix int.from_bytes to correctly convert bytes!
1 parent 5213eb3 commit b9e7ed4

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

py/objint.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ STATIC mp_obj_t int_from_bytes(uint n_args, const mp_obj_t *args) {
277277

278278
// convert the bytes to an integer
279279
machine_uint_t value = 0;
280-
for (uint i = 0; i < bufinfo.len; i++) {
281-
value += ((byte*)bufinfo.buf)[i];
280+
for (const byte* buf = bufinfo.buf + bufinfo.len - 1; buf >= (byte*)bufinfo.buf; buf--) {
281+
value = (value << 8) | *buf;
282282
}
283283

284284
return mp_obj_new_int_from_uint(value);

0 commit comments

Comments
 (0)