Menu

False positive: [shiftTooManyBits] on shifting 64-bit enum

Fan Zhang
2022-12-06
2022-12-06
  • Fan Zhang

    Fan Zhang - 2022-12-06
    #include <stdio.h>
    #include <stdint.h>
    
    enum big_enum { AAA = 0, BBB = UINT64_MAX };
    
    int main()
    {
        enum big_enum my_enum = BBB;
        printf("size: %zu. val=0x%X\n", sizeof(enum big_enum), my_enum >> 32);
        return 0;
    }
    
    Checking test.c ...
    test.c:9:68: error: Shifting 32-bit value by 32 bits is undefined behaviour [shiftTooManyBits]
        printf("size: %zu. val=0x%X\n", sizeof(enum big_enum), my_enum >> 32);
                                                                       ^
    
     
  • CHR

    CHR - 2022-12-06

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

     

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.