diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-13 12:40:50 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-13 12:40:50 +0100 |
commit | b9e7ed4ebcf8c7723dbb916e67c44e75fcb857f1 (patch) | |
tree | c05b2f494f34df0f78ca689af642d3bf361fd6f6 /py | |
parent | 5213eb35b52b0673fbc934c70274d1ebd82813af (diff) | |
download | micropython-b9e7ed4ebcf8c7723dbb916e67c44e75fcb857f1.tar.gz micropython-b9e7ed4ebcf8c7723dbb916e67c44e75fcb857f1.zip |
py: Oops, fix int.from_bytes to correctly convert bytes!
Diffstat (limited to 'py')
-rw-r--r-- | py/objint.c | 4 |
1 files changed, 2 insertions, 2 deletions
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); |