Skip to content

Commit 09a28c2

Browse files
committed
Fix allocation bug in nif_binary_split_2
This bug did not yield any crash because MIN_FREE_SPACE_SIZE is not 0 and allocated memory is more than was is requested. Signed-off-by: Paul Guyot <[email protected]>
1 parent 1950aaa commit 09a28c2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/libAtomVM/nifs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2648,8 +2648,8 @@ static term nif_binary_split_2(Context *ctx, int argc, term argv[])
26482648
int rest_size = bin_size - offset - pattern_size;
26492649
size_t rest_size_in_terms = term_sub_binary_heap_size(bin_term, rest_size);
26502650

2651-
// + 2 which is the result cons
2652-
if (UNLIKELY(memory_ensure_free(ctx, tok_size_in_terms + rest_size_in_terms + 2) != MEMORY_GC_OK)) {
2651+
// + 4 which is the result cons
2652+
if (UNLIKELY(memory_ensure_free(ctx, tok_size_in_terms + rest_size_in_terms + 4) != MEMORY_GC_OK)) {
26532653
RAISE_ERROR(OUT_OF_MEMORY_ATOM);
26542654
}
26552655

0 commit comments

Comments
 (0)