Staring in Cppcheck 1.89 I'm seeing a false positive that I can reproduce with this minimal example:
void function(int value, char *string)
{
char *ptr1 = NULL, *ptr2 = NULL;
unsigned long count = 0;
if(!string)
return;
ptr1 = string;
ptr2 = strrchr(string, 'a'); //The last instance
if(ptr2 == NULL)
return; //No such instances
while(ptr1 < ptr2)
{ //For each character up to the last instance of 'a'
count++;
ptr1++;
}
}
I know Cppcheck can't assume the programmer is using pointers properly in such an example (ie. both are pointers to the same string), but the warning doesn't seem accurate because both pointers are already checked for NULL.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Staring in Cppcheck 1.89 I'm seeing a false positive that I can reproduce with this minimal example:
I know Cppcheck can't assume the programmer is using pointers properly in such an example (ie. both are pointers to the same string), but the warning doesn't seem accurate because both pointers are already checked for NULL.
Thanks! I created https://trac.cppcheck.net/ticket/9315