Want to avoid this bug in your codebase? Try Greptile.
Avoid this bug!1 example
Integer underflow
Integer falls below minimum allowable value.
[ FAQ1 ]
What is integer underflow?
Integer underflow occurs when a calculation produces a numeric value below the minimum representable limit of an integer type, causing the number to wrap around or yield incorrect results. Unlike overflow, which involves exceeding the maximum value, underflow specifically refers to falling below the minimum bound. For example, subtracting a larger number from a smaller one in an unsigned integer type can cause a wraparound to a very large value instead of a negative number. Integer underflows introduce logical errors, unexpected behaviors, and potential security vulnerabilities in applications.
[ FAQ2 ]
How to prevent integer underflow
To prevent integer underflow, always validate and constrain arithmetic operations to ensure results stay within the allowable numeric limits of the data type used. Implement explicit underflow checks prior to operations that might yield values below the minimum limit. In languages like C or C++, use safer arithmetic practices, libraries, or built-in features to automatically handle boundary conditions. Additionally, regularly employ static analyzers and runtime assertions to proactively identify and mitigate underflow scenarios, maintaining robust arithmetic integrity in your code.
diff block
greptile
logic: Potential integer underflow if excluded_files + excluded_tags > processed. Add bounds checking or use saturating_sub.
suggested fix
+ println!("✅ Successfully processed: {} files", self.processed.saturating_sub(self.excluded_files).saturating_sub(self.excluded_tags));