Menu

FP: cert-INT31-c

mks004
2022-02-02
2022-02-02
  • mks004

    mks004 - 2022-02-02

    I am running into a suspected FP when checking this piece of code with Cppcheck 2.6 CERT addon:

    uint16_t * ptr;
    uint32_t   var = 65536;
    
    ptr = (uint16_t *)var;
    

    This is flagged as cert-INT31-c violation:

    ..\src\main.c:306:11: style: Ensure that integer conversions do not result in lost or misinterpreted data (casting 65536 to unsigned short) [cert-INT31-c]
        ptr = (uint16_t *)var;
              ^
    

    It complains about casting 65536 to unsigned short, however this is a conversion to a pointer to unsigned short, so should be valid on 32-bit machine.

     
  • Daniel Marjamäki

    Thanks! I can reproduce. I have created https://trac.cppcheck.net/ticket/10782

     

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.