From 0f649efceacd8f9eb921d5765dfa73b0771b1fcd Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Wed, 31 Jan 2024 01:19:23 -0500 Subject: use a single variable for tracking exit calls --- src/stdlib/_stdlib.h | 3 +-- src/stdlib/exit.c | 6 +++--- src/stdlib/quick_exit.c | 24 ++++++++++++------------ 3 files changed, 16 insertions(+), 17 deletions(-) (limited to 'src/stdlib') diff --git a/src/stdlib/_stdlib.h b/src/stdlib/_stdlib.h index de5a97d0..769f220b 100644 --- a/src/stdlib/_stdlib.h +++ b/src/stdlib/_stdlib.h @@ -20,8 +20,7 @@ struct __stdlib { struct atexit *next; struct atexit *prev; } atexit, at_quick_exit; - int exit_called; - int quick_exit_called; + enum { REGULAR = 1, QUICK } exit_called; unsigned int rand; char **environ; constraint_handler_t constraint_handler; diff --git a/src/stdlib/exit.c b/src/stdlib/exit.c index cd3175d6..42af83c7 100644 --- a/src/stdlib/exit.c +++ b/src/stdlib/exit.c @@ -14,13 +14,13 @@ _Noreturn void exit(int status) SIGNAL_SAFE(0); - if (__stdlib.quick_exit_called) { + if (__stdlib.exit_called == QUICK) { __stdlib.constraint_handler("Undefined behavior: exit() called after quick_exit()", NULL, 0); } - if (__stdlib.exit_called) { + if (__stdlib.exit_called == REGULAR) { __stdlib.constraint_handler("Undefined behavior: exit() called twice", NULL, 0); } - __stdlib.exit_called = 1; + __stdlib.exit_called = REGULAR; /* execute all atexit() registered functions in reverse order */ while (ae) { diff --git a/src/stdlib/quick_exit.c b/src/stdlib/quick_exit.c index 3d754604..9ad6780e 100644 --- a/src/stdlib/quick_exit.c +++ b/src/stdlib/quick_exit.c @@ -7,23 +7,23 @@ _Noreturn void quick_exit(int status) { SIGNAL_SAFE(1); - if (__stdlib.quick_exit_called) { + if (__stdlib.exit_called == QUICK) { __stdlib.constraint_handler("Undefined behavior: quick_exit() called twice", NULL, 0); - } - if (__stdlib.exit_called) { + } + if (__stdlib.exit_called) { __stdlib.constraint_handler("Undefined behavior: quick_exit() called after exit", NULL, 0); - } - __stdlib.quick_exit_called = 1; + } + __stdlib.exit_called = QUICK; /* execute all at_quick_exit() registered functions in reverse order */ struct atexit *ae = &(__stdlib.at_quick_exit); - while (ae) { - int i = ae->nfns; - while (i > 0) { - ae->fns[--i](); - } - ae = ae->prev; - } + while (ae) { + int i = ae->nfns; + while (i > 0) { + ae->fns[--i](); + } + ae = ae->prev; + } fflush(NULL); // fclose(all the things); -- cgit v1.2.1