# UndefinedBehaviorSanitizer

12 Hacker News commenters recommended UndefinedBehaviorSanitizer and 0 criticized it, November 2025 to November 2026. It was recommended in 5 of 13 months. It meets the Hacker Approved badge rule.

**Verdict:** Compiler instrumentation that makes a program abort with a clear error at runtime when it hits undefined behavior, so bugs are caught instead of hidden.

## Why people recommend it

- Catches undefined behavior at runtime (3 comments): "Under UBSan the program aborts with the runtime error, so the undefined behavior is caught rather than hidden." ([source](https://news.ycombinator.com/item?id=47044262)) "I'd be surprised if some combination of ASAN and UBSAN wouldn't catch this and similar dangling references" ([source](https://news.ycombinator.com/item?id=46098735)) "you should catch most trivial cases with e.g. ubsan" ([source](https://news.ycombinator.com/item?id=48204019))
- Clear error messages (2 comments): "Under UBSan the program aborts with the runtime error, so the undefined behavior is caught rather than hidden." ([source](https://news.ycombinator.com/item?id=47044262)) "It prints a nice error message about the exact issue as the author has shown." ([source](https://news.ycombinator.com/item?id=46937483))
- Used in routine testing (2 comments): "build and test with sanitizers (ASAN, UBSAN, TSAN) when not measuring performance" ([source](https://news.ycombinator.com/item?id=50032787)) "a mandatory test pass running with UBSan/ASan/Valgrind" ([source](https://news.ycombinator.com/item?id=50201093))

## Alternatives hackers recommend

- [Valgrind](https://hackerapproved.com/p/valgrind.md): 29 recommend
- [Miri](https://hackerapproved.com/p/miri.md): 26 recommend
- [AddressSanitizer](https://hackerapproved.com/p/addresssanitizer.md): 21 recommend
- [Go race detector](https://hackerapproved.com/p/go-race-detector.md): 5 recommend
- [ThreadSanitizer](https://hackerapproved.com/p/threadsanitizer.md): 5 recommend

## Cite as

Hacker Approved, "UndefinedBehaviorSanitizer", https://hackerapproved.com/p/undefinedbehaviorsanitizer/ (counts from 1,795,640 Hacker News comments, November 2025 to November 2026).
