It’s possible to catch the SIGABRT and continue the program with a longjump for example.
I wonder if this can lead to a stack overflow when I always call functions that invoke abort().
I need to know that because i want to use the assert macro (taht calls abort) in unit tests. If an assert fails, I want to continue with the next unit test.
abortdoesn’t need to clear the stack;longjmpwill “clear” it in that it will rewind the stack pointer back to the position ofsetjmp. If all else is correct, repeatedly invokinglongjmpandsetjmpwill not cause stack overflow.However,
longjmpwill skip normal execution path, which can call resource leaks in its own right. Consider this code:If the “… use s …” portion calls some function that
longjmps out of the code,freewon’t get a chance to get called and you will leak. The same applies to closing open files, sockets, freeing shared memory segments, reaping forked children, and so on.For this reason
longjmpis rarely used in C programming. My advice would be to avoidassertif you don’t mean the program to exit. Simply use another macro in your unit tests, or switch to a testing framework that provides one.