Skip to content

Commit ee65bbd

Browse files
committed
opcodesswitch.h: fix is_function/2 opcode
It must accept also registers as argument, so DECODE_COMPACT_TERM must be used. Fixes #1382. Signed-off-by: Davide Bettio <davide@uninstall.it>
1 parent 9a8c1f6 commit ee65bbd

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ memory error
6161
- Fixed issues with parsing of line references for stack traces
6262
- Fixed memory corruption issue with `erlang:make_tuple/2`
6363
- Fix potential use after free with code generated from OTP <= 24
64+
- Fix `is_function/2` guard
6465

6566
### Changed
6667

src/libAtomVM/opcodesswitch.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5353,18 +5353,20 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
53535353
DECODE_LABEL(label, pc)
53545354
term arg1;
53555355
DECODE_COMPACT_TERM(arg1, pc)
5356-
unsigned int arity;
5357-
DECODE_INTEGER(arity, pc)
5356+
term arity_term;
5357+
DECODE_COMPACT_TERM(arity_term, pc)
53585358

53595359
#ifdef IMPL_EXECUTE_LOOP
53605360
TRACE("is_function2/3, label=%i, arg1=%lx, arity=%i\n", label, arg1, arity);
53615361

5362-
if (term_is_function(arg1)) {
5362+
if (term_is_function(arg1) && term_is_integer(arity_term)) {
53635363
const term *boxed_value = term_to_const_term_ptr(arg1);
53645364

53655365
Module *fun_module = (Module *) boxed_value[1];
53665366
term index_or_module = boxed_value[2];
53675367

5368+
avm_int_t arity = term_to_int(arity_term);
5369+
53685370
uint32_t fun_arity;
53695371

53705372
if (term_is_atom(index_or_module)) {
@@ -5381,7 +5383,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
53815383
fun_arity = fun_arity_and_freeze - fun_n_freeze;
53825384
}
53835385

5384-
if (arity != fun_arity) {
5386+
if ((arity < 0) || (arity != (avm_int_t) fun_arity)) {
53855387
pc = mod->labels[label];
53865388
}
53875389
} else {

0 commit comments

Comments
 (0)