1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-29 01:40:26 +00:00

Fix unmarshalling integers directly, not through readint.

This commit is contained in:
Calvin Rose 2019-02-15 14:01:32 -05:00
parent 4d96ba3ba9
commit bdf03b4706
2 changed files with 12 additions and 8 deletions

View File

@ -564,10 +564,10 @@ static int32_t readint(UnmarshalState *st, const uint8_t **atdata) {
data += 2;
} else if (*data == LB_INTEGER) {
if (data + 5 > st->end) longjmp(st->err, UMR_EOS);
ret = (data[1] << 24) |
(data[2] << 16) |
(data[3] << 8) |
data[4];
ret = ((int32_t)(data[1]) << 24) |
((int32_t)(data[2]) << 16) |
((int32_t)(data[3]) << 8) |
(int32_t)(data[4]);
data += 5;
} else {
longjmp(st->err, UMR_EXPECTED_INTEGER);
@ -939,10 +939,10 @@ static const uint8_t *unmarshal_one(
/* Long integer */
EXTRA(5);
*out = janet_wrap_integer(
(data[1]) |
(data[2] << 8) |
(data[3] << 16) |
(data[4] << 24));
(data[4]) |
(data[3] << 8) |
(data[2] << 16) |
(data[1] << 24));
return data + 5;
case LB_REAL:
/* Real */

View File

@ -154,6 +154,10 @@
(testmarsh 1 "marshal small integers")
(testmarsh -1 "marshal integers (-1)")
(testmarsh 199 "marshal small integers (199)")
(testmarsh 5000 "marshal medium integers (5000)")
(testmarsh -5000 "marshal small integers (-5000)")
(testmarsh 10000 "marshal large integers (10000)")
(testmarsh -10000 "marshal large integers (-10000)")
(testmarsh 1.0 "marshal double")
(testmarsh "doctordolittle" "marshal string")
(testmarsh :chickenshwarma "marshal symbol")