fix(build.c): Check for successful reallocation

This commit is contained in:
Sau P 2024-11-25 15:41:22 +00:00 committed by anon
parent 5b534be7e4
commit 0306a40664

@ -390,7 +390,14 @@ void build(void) {
firstfile = lastfile;
lastfile = nsrcfiles;
if(invertedindex == true) {
srcoffset = realloc(srcoffset, (nsrcfiles + 1) * sizeof(*srcoffset));
long *tempoffset = realloc(srcoffset, (nsrcfiles + 1) * sizeof(*srcoffset));
/* Check for whether reallocation was a success */
if (tempoffset != NULL) {
srcoffset = tempoffset;
} else {
/* Cannot allocate any more memory, exit */
postfatal(PROGRAM_NAME ": cannot allocate any more memory\n");
}
}
/* sort the included file names */
qsort(srcfiles + firstfile, lastfile - firstfile, sizeof(*srcfiles), compare);