Skip to content

Commit 8bc200c

Browse files
committed
Merge pull request #1600 from bblaszkow06/fix/lists-reverse-segfault
Fix SEGFAULT in `nif_lists_reverse` A hardcoded `2` as roots count is invalid when the NIF is called as `lists:reverse/1`, possibly resulting in a SEGFAULT or `Found unknown boxed type: C` error during GC ---- These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents fd8a721 + 2f0c35c commit 8bc200c

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ memory error
6262
- Fixed memory corruption issue with `erlang:make_tuple/2`
6363
- Fix potential use after free with code generated from OTP <= 24
6464
- Fix `is_function/2` guard
65+
- Fixed segfault when calling `lists:reverse/1` (#1600)
6566

6667
### Changed
6768

src/libAtomVM/nifs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4598,7 +4598,7 @@ static term nif_lists_reverse(Context *ctx, int argc, term argv[])
45984598
RAISE_ERROR(BADARG_ATOM);
45994599
}
46004600

4601-
if (UNLIKELY(memory_ensure_free_with_roots(ctx, len * CONS_SIZE, 2, argv, MEMORY_CAN_SHRINK) != MEMORY_GC_OK)) {
4601+
if (UNLIKELY(memory_ensure_free_with_roots(ctx, len * CONS_SIZE, argc, argv, MEMORY_CAN_SHRINK) != MEMORY_GC_OK)) {
46024602
RAISE_ERROR(OUT_OF_MEMORY_ATOM);
46034603
}
46044604

0 commit comments

Comments
 (0)