Fix possible crashes

This commit is contained in:
Augusto Gunsch 2021-01-03 16:24:01 -03:00
parent f1f4f1ef8a
commit ea7f35c96d
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
2 changed files with 11 additions and 0 deletions

6
main.c
View File

@ -61,6 +61,12 @@ int main(int argc, char* argv[]) {
eprintf("%s", strerror(errno)); eprintf("%s", strerror(errno));
exit(1); exit(1);
} }
if(currunit->compiled == NULL) {
eprintf("Class '%s' is empty; file '%s'\n", currunit->parsed->name, currunit->file->name);
exit(1);
}
printlns(currunit->compiled->head, output); printlns(currunit->compiled->head, output);
fclose(output); fclose(output);
COMPILEUNIT* next = currunit->next; COMPILEUNIT* next = currunit->next;

View File

@ -244,6 +244,11 @@ TOKEN* tokenize(char* file) {
lasttype = curtype; lasttype = curtype;
} }
if(curitem == head) {
eprintf("File '%s' is empty\n", file);
exit(1);
}
lastitem->next = NULL; lastitem->next = NULL;
free(curitem); free(curitem);
freestr(tmptoken); freestr(tmptoken);