Menu

False positive, uninitVar

2020-08-07
2021-01-25
  • Fabian Cenedese

    Fabian Cenedese - 2020-08-07

    Hello

    I get an uninitVar message from this code:
    (uint32 is a typedef for unsigned long)


    volatile uint32* pIPIVPR;
    switch (GetCoreId()& 0x01) {
    

    // default:
    case 0 : pIPIVPR = INOS_HW_ADDR32(DF_INOS_P2020_MPIC_IPIVPR0); break;
    case 1 : pIPIVPR = INOS_HW_ADDR32(DF_INOS_P2020_MPIC_IPIVPR1); break;
    }

    *pIPIVPR &= 0x7fffffff;
    

    Uninitialized variable: pIPIVPR

    A number & 0x01 can only be two cases, 0 and 1, so the switch covers
    all cases. Still cppcheck thinks that pIPIVPR is uninitialized.

    Adding the commented out default: case didn't help although that would
    catch all not handled cases.

    So I think there are two problems: The value handling (& 0x01) and the
    switch default case which should both tell cppcheck that pIPIVPR is set.

    Thanks

     
  • CHR

    CHR - 2021-01-25

    I can't reproduce in either C or C++ mode with 2.3.

     

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.