Skip to content

Commit

Permalink
fixing exception handlers further
Browse files Browse the repository at this point in the history
  • Loading branch information
YSaxon committed May 10, 2024
1 parent 17f78fd commit a3b3f53
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ void raiseException(int status, char* formatstr, ...) {
}

void printException() {
if (current_exception_message != NULL) {
fprintf(stderr, "Error: %s\n", current_exception_message);
if (current_exception_message == NULL || strlen(current_exception_message) == 0){
fprintf(stderr, "Error thrown with no message\n");
} else {
fprintf(stderr, "%s\n", current_exception_message);
free(current_exception_message);
current_exception_message = NULL;
}
#ifdef use_backtrace
printStackTrace();
Expand All @@ -152,8 +156,15 @@ void unsetCodeSectionForSegfaultHandler() {
}

void handleSegfault(int signal) {
printf("hit handleSegfault\n");
vasprintf(&current_exception_message, "Segmentation fault in section: %s", (char*)SEGFAULT_SECTION);
if (current_exception_message != NULL) {
printf("Freeing current_exception_message which was unexpectedly not null: %s\n", current_exception_message);
free(current_exception_message);
current_exception_message = NULL;
}
current_exception_message = malloc(strlen("Segmentation fault in section: ") + strlen(SEGFAULT_SECTION) + 1);
strcpy(current_exception_message, "Segmentation fault in section: ");
strcat(current_exception_message, SEGFAULT_SECTION);
// vasprintf(&current_exception_message, "Segmentation fault in section: %s", (char*)SEGFAULT_SECTION);
siglongjmp(*current_exception_buffer, 1);
}

Expand Down Expand Up @@ -885,7 +896,7 @@ int main(int argc, char* argv[]) {

// Start the REPL
startRepl();

return 0;
}

Expand Down

0 comments on commit a3b3f53

Please sign in to comment.