Cppcheck doesn't seem to realize that when casted to a character type accessing a larger object at non-zero index is still within bounds. Funny enough, not using [] suppresses the warning, even though they're the same thing. Test case:
intmain(void){inta=4,b=8;unsignedchar*pa=&a;unsignedchar*pb=&b;for(inti=0;i<sizeofa;++i){pa[i]=pb[i];/* warns */*(pa+i)=*(pb+i);/* no warnings */}}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Cppcheck doesn't seem to realize that when casted to a character type accessing a larger object at non-zero index is still within bounds. Funny enough, not using
[]
suppresses the warning, even though they're the same thing. Test case:Which version do you use? I can't reproduce it with neither 2.8 nor head.
I was lagging a bit behind on v2.6.3, just upgraded to 2.8.2 the issue seems to be fixed.