Closed tueda closed 6 months ago
Revising this bug. The following code gives a segfault:
#do i=1,9
CreateSpectator S`i',"S`i'.spec";
#enddo
#do i=1,9
RemoveSpectator S`i';
#enddo
.end
==76175== Invalid read of size 1
==76175== at 0x2317A4: StrCmp (tools.c:1702)
==76175== by 0x216AC1: CoRemoveSpectator (spectator.c:255)
==76175== by 0x13ADEF: CompileStatement (compiler.c:658)
==76175== by 0x1DDA1D: PreProcessor (pre.c:1123)
==76175== by 0x21ADD9: main (startup.c:1688)
==76175== Address 0x0 is not stack'd, malloc'd or (recently) free'd
while reversing the order of the removal works:
#do i=1,9
CreateSpectator S`i',"S`i'.spec";
#enddo
#do i=9,1,-1
RemoveSpectator S`i';
#enddo
.end
Sounds like a simple memory bug?
The problem is that it tries to compare, here:
https://github.com/vermaseren/form/blob/b1f9041b7bb6f5dd4a149c87e70922ad9914b291/sources/spectator.c#L255
with AM.SpectatorFiles[0].name
which is null since it was set here in the previous iteration:
https://github.com/vermaseren/form/blob/b1f9041b7bb6f5dd4a149c87e70922ad9914b291/sources/spectator.c#L274
I suppose an "if not null" check would suffice, or you have to move all spectator files down in the array.
gives an error:
Valgrind output: