0

Unix signal 6, SIGABRT, is thrown when abort() is called in the program, or when a process attempts to (de)allocate invalid memory[1]. If I were to simply put abort() in a program like so:

int main(void)
{
    abort();
}

My system would print Aborted. But, if I were to actually attempt to deallocate invalid memory:

int main(void)
{
    free(main);
}

My system prints:

*** Error in `./a.out': munmap_chunk(): invalid pointer: 0x0000000000400536 ***
Aborted

Some systems give an entire stack trace.[2]

I want to turn off this extra information, so that when I attempt to mess with invalid memory, all I see is Aborted. How can I do that?

Note that this is not a compiler-specific thing, as GCC, TCC, and Clang all show the same thing.

MD XF
  • 7,860
  • 7
  • 40
  • 71
  • Even more important... How do you stop the error reporting, like Apport, Windows Error Reporting, Apple Crash Report, etc. They take all the sensitive information in your app, like passwords and private keys, and ship them off to a third party. – jww Jul 22 '17 at 21:29
  • If you don't want to get reports for undefined behaviour, how about just writing correct code? That way there is no output at all. – too honest for this site Jul 22 '17 at 21:49
  • Redirect stderr – stark Jul 22 '17 at 21:58
  • @Olaf - The reports can be generated for more than undefined behavior. An `assert` without `NDEBUG` defined will generate a `SIGABRT` because Posix specifies `assert` calls `abort()`, which raises `SIGABRT`. – jww Jul 23 '17 at 00:22
  • @JohnZwinck No, I do not want to catch it and implement my own ... thingy, I just want glibc to not display the extra information. – MD XF Jul 23 '17 at 03:26
  • @Olaf - *"constraint is not met (which would result in an illegal proram state -> UB in the final consequence)"* - Wrong. Undefined Behavior has a very specific meaning in C, C++ and Objective C. A program operating outside its parameters is not necessarily UB. Its just a buggy program. – jww Jul 23 '17 at 04:27
  • @Olaf - [Apple Technical Q&A QA1561](https://developer.apple.com/library/content/qa/qa1561/_index.html): *"How do I programmatically quit my iOS application?"* The answer is *"If during development or testing it is necessary to terminate your application, the abort function, or assert macro is recommended"*. Also see [Proper way to exit iPhone application?](https://stackoverflow.com/a/2980740/608639) No Undefined Behavior required. – jww Jul 23 '17 at 04:39
  • @jww: I will not further discuss this. It has been unrelated to the question and my comment from the beginning. You put words in my mouth and I made the mistake to bite. Therefore I deleted my other comments. Please remember comments are not for discussion. (Finally: Please provide the ISO/IEC number of that Apple document. Vendor-specific documents are hardly authoritative) – too honest for this site Jul 23 '17 at 04:47
  • @Olaf - I thought so, thanks. – jww Jul 23 '17 at 04:49
  • 1
    I don't think that this is a duplicate of the question to intercept aborts. These outputs are produced *before* `abort()` is called. Whilst it's still a good idea to write code that exits cleanly, I disagree that the answers to that question would be any use for this - voting to reopen. – Toby Speight Aug 03 '17 at 08:08

0 Answers0