Use __builtin_trap instead of null pointer dereference to abort

This fixes a warning from Apple's clang compiler:

    [ 34%] Building CXX object CMakeFiles/libtesseract.dir/src/ccutil/errcode.cpp.o
    /Users/travis/build/stweil/tesseract/src/ccutil/errcode.cpp:83:7: warning: indirection of non-volatile null pointer will be deleted, not trap [-Wnull-dereference]
          *reinterpret_cast<int*>(0) = 0;
          ^~~~~~~~~~~~~~~~~~~~~~~~~~
    /Users/travis/build/stweil/tesseract/src/ccutil/errcode.cpp:83:7: note: consider using __builtin_trap() or qualifying pointer with 'volatile'

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2019-02-15 17:08:29 +01:00
parent 4bd18c4c1b
commit 38861be639

View File

@ -77,10 +77,14 @@ const char *format, ... // special message
//err_exit();
case ABORT:
#if !defined(NDEBUG)
// Create a deliberate segv as the stack trace is more useful that way.
// This is done only in debug builds, because the error message
// "segmentation fault" confuses most normal users.
// Create a deliberate abnormal exit as the stack trace is more useful
// that way. This is done only in debug builds, because the
// error message "segmentation fault" confuses most normal users.
#if defined(__GNUC__)
__builtin_trap();
#else
*reinterpret_cast<int*>(0) = 0;
#endif
#endif
abort();
default: