From 5338a5a8d5e4ebad496ee38aafa06059631db4e7 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Thu, 20 Sep 2018 21:49:41 +0200 Subject: [PATCH] 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 --- src/ccutil/errcode.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ccutil/errcode.cpp b/src/ccutil/errcode.cpp index 849be563cc..ce4377de30 100644 --- a/src/ccutil/errcode.cpp +++ b/src/ccutil/errcode.cpp @@ -71,7 +71,6 @@ 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: @@ -79,9 +78,13 @@ const char *format, ... // special message 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(0) = 0; +#endif + abort(); default: BADERRACTION.error ("error", ABORT, nullptr); }