From b9e7ed4ebcf8c7723dbb916e67c44e75fcb857f1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 13 Apr 2014 12:40:50 +0100 Subject: py: Oops, fix int.from_bytes to correctly convert bytes! --- py/objint.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'py') diff --git a/py/objint.c b/py/objint.c index 6db1969c54..2eabff8d4e 100644 --- a/py/objint.c +++ b/py/objint.c @@ -277,8 +277,8 @@ STATIC mp_obj_t int_from_bytes(uint n_args, const mp_obj_t *args) { // convert the bytes to an integer machine_uint_t value = 0; - for (uint i = 0; i < bufinfo.len; i++) { - value += ((byte*)bufinfo.buf)[i]; + for (const byte* buf = bufinfo.buf + bufinfo.len - 1; buf >= (byte*)bufinfo.buf; buf--) { + value = (value << 8) | *buf; } return mp_obj_new_int_from_uint(value); -- cgit v1.2.3