Skip to content
Advertisement

C realloc assertion

Not sure why I’m getting the following error when trying to use realloc:

malloc.c:2401: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize – 1)) == 0)’ failed. Aborted (core dumped)

Here is the code fragment

JavaScript

Advertisement

Answer

In your loop, you check for nstructs > maxstructs, so when nstructs==1024 and maxstructs==1024, you don’t realloc, but access myStructs[1024], which is one past the end. You would need nstructs>=maxstructs in your test condition.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement