Menu

Inconsistent behavior of the unreadVariable rule

safans
3 days ago
3 days ago
  • safans

    safans - 3 days ago

    Hi, I found an inconsistent behavior in the unreadVariable rule. The following two programs are seamntics equivalent.

    However, CppCheck reported an unreadVariable warning in the first program, but no warnings in the second program. So, I think this is an inconsistent behaviour.

    The First Program

    #include <stdio.h>
    #include <string.h>
    int main() {
      char str[20];
      for (int i = 0; i < 16; ++i)
        str[i] = "0123456789abcdef"[i];
      return 0;
    }
    

    The Second Program

    #include <stdio.h>
    int main()
    {
        char str[20];
        strcpy(str, "0123456789abcdef");
        return 0;
    }
    

    Version: Cppcheck 2.22 dev

     
  • CHR

    CHR - 3 days ago

    Thanks for reporting, see https://trac.cppcheck.net/ticket/14835

     

Log in to post a comment.

Auth0 Logo