Call atexit handlers properly, avoiding a NPE and seg fault every time a
authorDavid Given <dg@cowlark.com>
Sun, 9 Sep 2018 16:51:00 +0000 (18:51 +0200)
committerDavid Given <dg@cowlark.com>
Sun, 9 Sep 2018 16:51:00 +0000 (18:51 +0200)
program exits.

lang/cem/libcc.ansi/sys/exit/exit.c

index 7f86132..d16db6c 100644 (file)
@@ -15,8 +15,8 @@ int __funccnt = 0;
 void exit(int status)
 {
        /* "Called in reversed order of their registration" */
-       while (__funccnt >= 0)
-               (*__functab[__funccnt])();
+       while (__funccnt)
+               (*__functab[--__funccnt])();
 
        _exit(status);
 }