Cppcheck-1.90 does not speculate about user input like that. If it doesn't have any idea what the value is then it doesn't assume anything.
In the next Cppcheck release I want to add a new analysis mode that will be "sound" - it will detect all bugs. With that analysis the bugs in your code could be detected. However I will only add checks for "Division by zero" and "uninitialized variables" in the first release. I think "overflows" will be added next.. I don't promise anything but I'd think that will be added in the middle of 2020.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
$~/cppcheck/cppcheck--bug-hunting divbyzero.c Checkingdivbyzero.c...divbyzero.c:10:5:error:Thereisdivision,cannotdeterminethattherecan't be a division by zero. [verificationDivByZero] a /= 0; ^divbyzero.c:11:5: error: There is division, cannot determine that there can'tbeadivisionbyzero.[verificationDivByZero]b/=0;^divbyzero.c:12:5:error:Thereisdivision,cannotdeterminethattherecan't be a division by zero. [verificationDivByZero] c /= 0; ^divbyzero.c:13:5: error: There is division, cannot determine that there can'tbeadivisionbyzero.[verificationDivByZero]d/=0;^
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Version: 1.90
Platform: Ubuntu 18.04
Test Code:
Result:
No bugs were reported by cppcheck even with --enable=all and/or --inconclusive.
Question:
Is there any way I could increase the aggressiveness of cppcheck so that it would detect these bugs?
Thanks!
Cppcheck-1.90 does not speculate about user input like that. If it doesn't have any idea what the value is then it doesn't assume anything.
In the next Cppcheck release I want to add a new analysis mode that will be "sound" - it will detect all bugs. With that analysis the bugs in your code could be detected. However I will only add checks for "Division by zero" and "uninitialized variables" in the first release. I think "overflows" will be added next.. I don't promise anything but I'd think that will be added in the middle of 2020.
If you want to.. feel free to write some test cases for "division by zero" so we can ensure these will be detected.
Thank you Daniel! Here is a test case for division by zero I made. You may add more variable types, such as unsigned type, as needed.
Those are detected already: