SIGINT handler throws uncaught exception and might have UB
mo-xiaoming opened this issue · comments
Setup
OS: macOS catalina
LLVM: brew installed llvm: stable 12.0.0
Compiler: Apple clang version 12.0.0 (clang-1200.0.31.1)
readline: brew installed readline: stable 8.1
hobbes was built with LLVM_DIR=/usr/local/Cellar/llvm/12.0.0_1/lib/cmake
Uncaught exception
$ ./hi
hi : an interactive shell for hobbes
type ':h' for help on commands
> 3 + 5
8
> ^C libc++abi: terminating with uncaught exception of type hi::interruption_error: std::exception
Abort trap: 6
UB
Might be unrelated to the above problem, but the SIGINT handler might have some issues
[[noreturn]] void interruptEval(int) {
siglongjmp(continueInterrupt, 42);
}
Although siglongjmp
family can be used in C signal handling(reference), it is not among the list of C++ signal-safe
functions(cppreference), which make it UB
siglongjmp
jumps the execution to
void installInterruptHandler() {
if (sigsetjmp(continueInterrupt,1) == 0) {
signal(SIGINT, &interruptEval);
} else if (!terminating) {
throw interruption_error();
} else {
exit(-1);
}
}
which throws interruption_error
, and throwing in a signal handler is an UB as well
Agreed, throwing in a signal handler is an UB indeed. Do you mind pushing a pull request for review?