Skip to content

Commit 5338a5a

Browse files
committed
Don't trigger a deliberate SIGSEGV for fatal errors in release code
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 <[email protected]>
1 parent cefb62b commit 5338a5a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/ccutil/errcode.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,20 @@ const char *format, ... // special message
7171
// %s is needed here so msg is printed correctly!
7272
fprintf(stderr, "%s", msg);
7373

74-
int* p = nullptr;
7574
switch (action) {
7675
case DBG:
7776
case TESSLOG:
7877
return; //report only
7978
case TESSEXIT:
8079
//err_exit();
8180
case ABORT:
81+
#if !defined(NDEBUG)
8282
// Create a deliberate segv as the stack trace is more useful that way.
83-
if (!*p)
84-
abort();
83+
// This is done only in debug builds, because the error message
84+
// "segmentation fault" confuses most normal users.
85+
*reinterpret_cast<int*>(0) = 0;
86+
#endif
87+
abort();
8588
default:
8689
BADERRACTION.error ("error", ABORT, nullptr);
8790
}

0 commit comments

Comments
 (0)