Address #336 case 3

Fix error condition for bad abstract types - don't return NULL, panic.
This commit is contained in:
Calvin Rose 2020-04-05 17:38:14 -05:00
parent 553e38ffd6
commit 5bbd507858
3 changed files with 11 additions and 9 deletions

View File

@ -1098,7 +1098,7 @@ static const uint8_t *unmarshal_one_abstract(UnmarshalState *st, const uint8_t *
Janet key;
data = unmarshal_one(st, data, &key, flags + 1);
const JanetAbstractType *at = janet_get_abstract_type(key);
if (at == NULL) return NULL;
if (at == NULL) goto oops;
if (at->unmarshal) {
JanetMarshalContext context = {NULL, st, flags, data, at};
*out = janet_wrap_abstract(at->unmarshal(&context));
@ -1107,7 +1107,8 @@ static const uint8_t *unmarshal_one_abstract(UnmarshalState *st, const uint8_t *
}
return context.data;
}
return NULL;
oops:
janet_panic("invalid abstract type");
}
static const uint8_t *unmarshal_one(

View File

@ -212,5 +212,6 @@
(assert-error "unmarshal errors 1" (unmarshal @"\xd6\xb9\xb9"))
(assert-error "unmarshal errors 2" (unmarshal @"\xd7bc"))
(assert-error "unmarshal errors 3" (unmarshal "\xd3\x01\xd9\x01\x62\xcf\x03\x78\x79\x7a" load-image-dict))
(end-suite)

View File

@ -8,15 +8,15 @@
(def cases [
nil
"abc"
:def
'hij
123
(int/s64 123)
"7"
@ -28,12 +28,12 @@
{:a 123}
@{:b 'xyz}
(peg/compile
'{:a (* "a" :b "a")
:b (* "b" (+ :a 0) "b")
:main (* "(" :b ")")})
(fn f [a] (fn [] {:ab a}))
(fn f [a] (print "hello world!"))