Menu

False positive: bit and misinterpreted as address-of operator

2023-02-20
2023-02-20
  • Matěj Plch

    Matěj Plch - 2023-02-20

    Cppcheck emits warning on the following code:

    int bit_and()
    {
      return int{0b00010101} & 0b00000111;
    }
    
    [test.cpp:3]: (portability) Returning an address value in a function with integer (int/long/etc) return type is not portable across different platforms and compilers. For example in 32-bit Windows and Linux they are same width, but in 64-bit Windows and Linux they are of different width. In worst case you end up casting 64-bit address down to 32-bit integer. The safe way is to always return an integer.
    

    It seems to be triggered by the braces in int{0b00010101}, it does not warn when using parentheses int(0b00010101).

     
  • CHR

    CHR - 2023-02-20

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

     

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.