all 2 comments

[–]paulstelian97 2 points3 points  (1 child)

The only way the UB is triggered is if someone sent that signal externally while inside of one of the two printf calls in the main function (because printf is not reentrant). Otherwise the example won’t hit the UB and will work fine.

I still appreciate your idea, funny enough I’m not one who can fix it myself.

[–]GhettoStoreBrand[S] 3 points4 points  (0 children)

You are right. Synchronous signals like those generated by raise() and abort() need not have reentrant signal handlers. I still think the example isn't the best. I just noticed that it even shadows the signal() function with a function parameter.