A Taxonomy of Bugs
a year ago
- #programming
- #bugs
- #debugging
- Debugging is an undervalued skill often learned through experience rather than formal education.
- The default debugging strategy involves reproducing the bug, using a debugger to step through code, and comparing actual behavior with expectations.
- Some programmers prefer printf() and logging over debuggers, though debuggers are generally more efficient.
- Typos are common bugs where the code compiles but doesn't behave as intended due to a typing mistake.
- To spot typos, proofread carefully or use debugging tools to step through the code.
- Prevent typos by enabling compiler warnings, using source code formatters, and writing code in a way that reduces typo likelihood.
- Logical errors occur when the code doesn't perform as intended, often due to flawed reasoning.
- Simplify expressions and reduce code paths to minimize logical errors.
- Unexpected initial conditions can cause bugs if the code assumes a certain state that isn't met.
- Use asserts to make expectations about initial conditions explicit.
- Memory leaks happen when allocated memory isn't freed, leading to resource wastage.
- Instrument memory allocations to track and detect leaks.
- Memory overwrites occur when code writes to memory it doesn't own, causing crashes or undefined behavior.
- Use custom allocators like end-of-page allocators to catch memory overwrites early.
- Race conditions arise in multithreaded environments when threads access shared data unpredictably.
- Simplify threading code and use tools like Clang's thread sanitizer to detect race conditions.
- Design flaws occur when the underlying logic of the code is flawed, requiring a redesign rather than a fix.
- Third-party bugs are issues in external libraries or tools, requiring either fixes from the vendor or workarounds.
- Failed specifications happen when API documentation is unclear or incomplete, leading to misuse.
- Hard-to-reproduce bugs require stress testing or extensive logging to identify and fix.
- Statistical analysis helps prioritize bugs based on frequency and impact.
- Compiler bugs are rare but can occur, requiring code adjustments or switching compilers.