Menu

objectIndex check does not take pointer type into account

NRK
2022-08-15
2022-08-16
  • NRK

    NRK - 2022-08-15

    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:

    int main(void)
    {
        int a = 4, b = 8;
    
        unsigned char *pa = &a;
        unsigned char *pb = &b;
    
        for (int i = 0; i < sizeof a; ++i) {
            pa[i] = pb[i]; /* warns */
            *(pa + i) = *(pb + i); /* no warnings */
        }
    }
    
     
  • CHR

    CHR - 2022-08-16

    Which version do you use? I can't reproduce it with neither 2.8 nor head.

     
  • NRK

    NRK - 2022-08-16

    I was lagging a bit behind on v2.6.3, just upgraded to 2.8.2 the issue seems to be fixed.

     
    👍
    1

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.