Overview
- Bug Type:
- Off-by-one / boundary error
- Category:
- Functional Logic & Control Flow
Definition
Index/range/loop bounds are miscalculated by one, causing omission, duplication, or out-of-range access.
How to fix Off-by-one / boundary error?
Clarify inclusive vs exclusive bounds; prefer length-based loops and safe slicing; add boundary tests and fuzzers
Symptoms
Observable signs that may indicate Off-by-one / boundary error:
- First/last element skipped or duplicated.
- Index out-of-range on boundary inputs.
- Allocated size differs by exactly one element.
Example Errors:
- IndexError: list index out of range
- ArrayIndexOutOfBoundsException
- Buffer overread/overwrite detected
