diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-02-20 13:25:05 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-02-20 13:25:05 +0200 |
commit | a8d31b28bcf640579c013eeeb2e814c317e59111 (patch) | |
tree | 6080213056ea7fa211a0af6153b4245309840e38 /py | |
parent | a1aba36febc8ff1107114da2ffdac398206ebb7e (diff) | |
download | micropython-a8d31b28bcf640579c013eeeb2e814c317e59111.tar.gz micropython-a8d31b28bcf640579c013eeeb2e814c317e59111.zip |
emitbc: Correct buffer sizes for varlen int encoding.
Assuming we have truncating (floor) division, way to do ceiling division
by N is to use formula (x + (N-1)) / N. Specifically, 63 bits, if stored
7 bits per byte, require exactly 9 bytes. 64 bits overflow that and require
10 bytes.
Diffstat (limited to 'py')
-rw-r--r-- | py/emitbc.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/py/emitbc.c b/py/emitbc.c index 9fab977909..b26da0e706 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -109,7 +109,7 @@ STATIC void emit_write_byte_code_byte_byte(emit_t* emit, byte b1, uint b2) { STATIC void emit_write_byte_code_uint(emit_t* emit, uint num) { // We store each 7 bits in a separate byte, and that's how many bytes needed - byte buf[(BYTES_PER_WORD * 8 + 7) / 7]; + byte buf[(BYTES_PER_WORD * 8 + 6) / 7]; byte *p = buf + sizeof(buf); // We encode in little-ending order, but store in big-endian, to help decoding do { @@ -128,7 +128,7 @@ STATIC void emit_write_byte_code_byte_int(emit_t* emit, byte b1, machine_int_t n emit_write_byte_code_byte(emit, b1); // We store each 7 bits in a separate byte, and that's how many bytes needed - byte buf[(BYTES_PER_WORD * 8 + 7) / 7]; + byte buf[(BYTES_PER_WORD * 8 + 6) / 7]; byte *p = buf + sizeof(buf); // We encode in little-ending order, but store in big-endian, to help decoding do { |