Don't trigger a deliberate SIGSEGV for fatal errors in release code · tesseract-ocr/tesseract@5338a5a (original) (raw)

Original file line number Diff line number Diff line change
@@ -71,17 +71,20 @@ const char *format, ... // special message
71 71 // %s is needed here so msg is printed correctly!
72 72 fprintf(stderr, "%s", msg);
73 73
74 -int* p = nullptr;
75 74 switch (action) {
76 75 case DBG:
77 76 case TESSLOG:
78 77 return; //report only
79 78 case TESSEXIT:
80 79 //err_exit();
81 80 case ABORT:
81 +#if !defined(NDEBUG)
82 82 // 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();
85 88 default:
86 89 BADERRACTION.error ("error", ABORT, nullptr);
87 90 }