History

Bug in module reader.

arr committed 9 years ago

Commit 4afaca41 parent cb408a11 file · +12 −12Browse files

Showing the changes to src/vm/module_reader.cpp (1 of 1 file). Show all

Unified · Split

src/vm/module_reader.cpp+12−12
@@ -51,7 +51,7 @@ namespace · 50 unmodified lines
5151 // Read the next operand as defined in the Dis VM specification.
5252 std::tuple<bool, operand_t> read_next_operand(util::buffered_reader_t &reader)
5353 {
54− auto result = operand_t{ 0 };
54+ operand_t result;
5555
5656 // Converting stack allocation to buffer since max size of operand is a machine word
5757 byte_t buffer[sizeof(result)];
@@ -59,16 +59,16 @@ namespace · 1 unmodified line
5959 if (!reader.get_next_bytes(1, buffer))
6060 return std::make_tuple(false, 0);
6161
62− switch (buffer[0] & 0xc0)
62+ result = buffer[0];
63+ switch (result & 0xc0)
6364 {
6465 case 0x00:
6566 // 1 byte operand
66− result = buffer[0];
6767 break;
6868
6969 case 0x40:
7070 // 1 byte operand - Preserve sign
71− result = buffer[0] | ~0x7f;
71+ result |= ~0x7f;
7272 break;
7373
7474 case 0x80:
@@ -77,12 +77,12 @@ namespace · 2 unmodified lines
7777 return std::make_tuple(false, 0);
7878
7979 // Preserve sign
80− if ((buffer[0] & 0x20) != 0)
81− buffer[0] |= ~0x3f;
80+ if ((result & 0x20) != 0)
81+ result |= ~0x3f;
8282 else
83− buffer[0] &= 0x3f;
83+ result &= 0x3f;
8484
85− result = (buffer[0] << 8);
85+ result = (result << 8);
8686 result |= buffer[1];
8787 break;
8888
@@ -92,12 +92,12 @@ namespace · 3 unmodified lines
9292 return std::make_tuple(false, 0);
9393
9494 // Preserve sign
95− if ((buffer[0] & 0x20) != 0)
96− buffer[0] |= ~0x3f;
95+ if ((result & 0x20) != 0)
96+ result |= ~0x3f;
9797 else
98− buffer[0] &= 0x3f;
98+ result &= 0x3f;
9999
100− result = (buffer[0] << 24);
100+ result = (result << 24);
101101 result |= (buffer[1] << 16);
102102 result |= (buffer[2] << 8);
103103 result |= buffer[3];