Menu

Calculates length of std::array wrong (or not at all)

2025-02-24
2025-03-01
  • Stefan Petersen

    Stefan Petersen - 2025-02-24

    Hello,

    I downloaded 2.17.0 and tried it. I got a warning from cppcheck on some code that I then tried to minimize to the following:
    https://godbolt.org/z/cKeEePGz4

    It might be considered strange code, but it is mostly for demonstration purpose.

    The length of the std::array is 6 * sizeof(uint16_t), aka 12. But cppcheck warns that the array is only 6 positions, and hence signals out-of-bounds. If I give the length of the array directly as 12, it works.

    Thanks,
    /Stefan Petersen

     

    Last edit: Stefan Petersen 2025-02-24
  • CHR

    CHR - 2025-02-24

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

     
  • Stefan Petersen

    Stefan Petersen - 2025-03-01

    Thank you for fixing a ticket. And thank you for cppcheck.

    /Stefan Petersen

     

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.