Skip to content

Commit 8097908

Browse files
committed
Merge pull request #1728 from pguyot/w26/fix-crash-no-line
Fix a crash when a module has no line information 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 4e228ac + 7ab3ebc commit 8097908

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/libAtomVM/module.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -336,19 +336,21 @@ Module *module_new_from_iff_binary(GlobalContext *global, const void *iff_binary
336336
num_offsets++;
337337
item = item->next;
338338
}
339-
mod->line_refs_offsets = malloc(num_offsets * sizeof(unsigned int));
340-
if (IS_NULL_PTR(mod->line_refs_offsets)) {
341-
fprintf(stderr, "Warning: Unable to allocate space for line refs offset, module has %zu offsets. Line information in stacktraces may be missing\n", num_offsets);
342-
} else {
343-
size_t index = 0;
344-
item = line_refs.next;
345-
while (item != &line_refs) {
346-
struct LineRefOffset *offset = CONTAINER_OF(item, struct LineRefOffset, head);
347-
mod->line_refs_offsets[index] = offset->offset;
348-
index++;
349-
item = item->next;
339+
if (num_offsets > 0) {
340+
mod->line_refs_offsets = malloc(num_offsets * sizeof(unsigned int));
341+
if (IS_NULL_PTR(mod->line_refs_offsets)) {
342+
fprintf(stderr, "Warning: Unable to allocate space for line refs offset, module has %zu offsets. Line information in stacktraces may be missing\n", num_offsets);
343+
} else {
344+
size_t index = 0;
345+
item = line_refs.next;
346+
while (item != &line_refs) {
347+
struct LineRefOffset *offset = CONTAINER_OF(item, struct LineRefOffset, head);
348+
mod->line_refs_offsets[index] = offset->offset;
349+
index++;
350+
item = item->next;
351+
}
352+
mod->line_refs_offsets_count = num_offsets;
350353
}
351-
mod->line_refs_offsets_count = num_offsets;
352354
}
353355
}
354356
// Empty the list

0 commit comments

Comments
 (0)