Commit a8d31b28 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

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.
parent a1aba36f
......@@ -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 {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment