Menu ▾ ▴

False negative: pointer-to-integer conversion in compound assignment

Rodri
2026-09-29
2026-09-30
  • Rodri

    Rodri - 2026-09-29

    Hi, I found a false negative regarding the rule AssignmentAddressToInteger.

    Cppcheck misses the pointer-to-integer conversion when it is written as a compound assignment.

    int f(int *p) {
      int a = 0;
      a += p;
      return a + 4;
    }
    

    Actual result

    Cppcheck does not report AssignmentAddressToInteger. Replacing a += p with a = a + p produces the warning.

    Expected result

    Cppcheck should also report the pointer-to-integer conversion in the compound assignment.

    Verification

    The issue was reproduced with:

    cppcheck --output-format=xmlv2 --enable=all assignment_compound.c
    

    Version: 2.21.0

     
  • CHR

    CHR - 2026-09-30

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15075

     

Log in to post a comment.