From 3ff4df42ff2d275aeebbbd455c2747a68a58c8ba Mon Sep 17 00:00:00 2001 From: Thomas Arts Date: Mon, 3 Jun 2019 13:43:49 +0200 Subject: [PATCH] Make sure arguments not provided are maskes 2#00. --- src/aeb_fate_code.erl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/aeb_fate_code.erl b/src/aeb_fate_code.erl index 3a1efe9..a60858b 100644 --- a/src/aeb_fate_code.erl +++ b/src/aeb_fate_code.erl @@ -345,8 +345,8 @@ deserialize_op(Op, Rest, Code) -> end. deserialize_n_args(N, <>) when N =< 4 -> - ArgMods = lists:sublist([M0, M1, M2, M3], N), - %% If N == 1 then we take M0 and don't care about the others. Should we check that the others are 0?? + {ArgMods, Zeros} = lists:split(N, [M0, M1, M2, M3]), + assert_zero(Zeros), lists:mapfoldl(fun(M, Acc) -> case bits_to_modifier(M) of stack -> @@ -358,7 +358,8 @@ deserialize_n_args(N, <>) when N =< 4 -> end, Rest, ArgMods); deserialize_n_args(N, <>) when N =< 8 -> - ArgMods = lists:sublist([M0, M1, M2, M3, M4, M5, M6, M7], N), + {ArgMods, Zeros} = lists:split(N, [M0, M1, M2, M3, M4, M5, M6, M7]), + assert_zero(Zeros), lists:mapfoldl(fun(M, Acc) -> case bits_to_modifier(M) of stack -> @@ -381,3 +382,10 @@ deserialize_symbols(Table) -> deserialize_annotations(AnnotationsBin) -> ?FATE_MAP_VALUE(Annotations) = aeb_fate_encoding:deserialize(AnnotationsBin), Annotations. + +assert_zero([]) -> + true; +assert_zero([0|Rest]) -> + assert_zero(Rest); +assert_zero([_|_]) -> + error(argument_defined_outside_range).