The return of NS_ABORT_IF_FALSE

After five years in hiding, NS_ABORT_IF_FALSE has returned. Please use it instead of NS_ASSERTION in situations where failure is likely to lead to memory corruption. By aborting rather than asserting, you ensure that debug-build users focus on the cause of the corruption rather than whatever random crash results from the corruption. This leads to happier debugging and better bug reports.

Of course, sometimes it's better to prevent the memory corruption entirely, e.g. by adding a run-time check or by making all builds abort (not just debug builds).

2 Responses to “The return of NS_ABORT_IF_FALSE”

  1. Jesse Ruderman Says:

    As a bonus, you’re guaranteed to have a stack trace: https://bugzilla.mozilla.org/show_bug.cgi?id=434076. On Leopard, you can also get a stack trace from the system crash reporter.

  2. Jeff Walden Says:

    Hrm, not sure how I forgot to close the bug. Anyway, reviews really should just require N_A_I_F unless the assert’s being hit in known circumstances that are hard to fix quickly, not just in superbad cases.