Fixed assembler bug that caused crash on IR array resize. Added line editor app.

This commit is contained in:
Anachronaut
2026-08-17 23:26:21 -04:00
parent 1d1a14318c
commit e3100b4718
87 changed files with 2201 additions and 74 deletions
+15 -3
View File
@@ -166,8 +166,18 @@ int loadFile(intermediateElement **intermediateArray, char *fileName, int *inter
exit(1);
}
// Read off tokens.
while (readToken(&(*intermediateArray)[*intermediateIndex], file, &lineNumber)) {
if ((size_t)*intermediateIndex >= *arraySize - 1) {
//
// ROOM IS MADE BEFORE THE TOKEN IS READ, not after. readToken writes into the element
// at the current index, so a check that came afterwards was checking whether the write
// that had already happened was allowed to. It survived for a long time because the
// margin usually covered it, and stopped surviving when a file grew past a doubling:
// several paths below take a SECOND element for one token - an #Include takes one for
// the file name, #Align and #Reserve take one for the count - so the index can move by
// two in an iteration and step straight over a margin of one.
//
// The margin is two for that reason, which is the most any one iteration uses.
while (1) {
if ((size_t)*intermediateIndex + 2 >= *arraySize) {
size_t grownSize = *arraySize * 2; // Double the size of the array.
// Into a temporary, so that the old allocation is still ours to free if
// this fails, rather than being lost the moment realloc returns NULL.
@@ -184,7 +194,9 @@ int loadFile(intermediateElement **intermediateArray, char *fileName, int *inter
*intermediateArray = grown;
*arraySize = grownSize;
}
//printf("Token number %d\n", intermediateIndex);
if (!readToken(&(*intermediateArray)[*intermediateIndex], file, &lineNumber)) {
break;
}
// Go ahead and mark what we already know about this token.
(*intermediateArray)[*intermediateIndex].fileName = fileName;
(*intermediateArray)[*intermediateIndex].lineNumber = lineNumber;