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.
pull/313/head
Paul Sokolovsky 2014-02-20 13:25:05 +02:00
rodzic a1aba36feb
commit a8d31b28bc
1 zmienionych plików z 2 dodań i 2 usunięć

Wyświetl plik

@ -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 {