Skip to content

Commit

Permalink
Don't trigger a deliberate SIGSEGV for fatal errors in release code
Browse files Browse the repository at this point in the history
The error message "segmentation fault" confuses most users,
so enforce a segmentation fault only in debug code.

Release code simply calls the abort function.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Sep 20, 2018
1 parent cefb62b commit 5338a5a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/ccutil/errcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,20 @@ const char *format, ... // special message
// %s is needed here so msg is printed correctly!
fprintf(stderr, "%s", msg);

int* p = nullptr;
switch (action) {
case DBG:
case TESSLOG:
return; //report only
case TESSEXIT:
//err_exit();
case ABORT:
#if !defined(NDEBUG)
// Create a deliberate segv as the stack trace is more useful that way.
if (!*p)
abort();
// This is done only in debug builds, because the error message
// "segmentation fault" confuses most normal users.
*reinterpret_cast<int*>(0) = 0;
#endif
abort();
default:
BADERRACTION.error ("error", ABORT, nullptr);
}
Expand Down

0 comments on commit 5338a5a

Please sign in to comment.