Menu

std::array incorrect bounds

2019-08-28
2019-10-04
  • Benjamin Combee

    Benjamin Combee - 2019-08-28

    I saw this last night checking some of our internal code and shrunk down to this test case:

    #include <array>
    
    constexpr int blockLen = 10;
    void foo(std::array<uint8_t, blockLen * 2>& a) {
        a[2] = 2;
    }
    

    this gives the error arrayIndexOutOfBounds Array 'a[2]' accessed at index 2, which is out of bounds, because it looks like the code that computes the size of std::array doesn't handle the constexpr value correctly. However, changing that line to "#define blockLen 10" also gave the same error. This reproduces with 1.88 and top-of-tree from git.

     
  • Paul Fultz

    Paul Fultz - 2019-08-28

    This is related to this issue reported here:

    https://trac.cppcheck.net/ticket/9202

     
  • Barrett Lowe

    Barrett Lowe - 2019-09-18

    That link seems to be dead. Ticket 9202 doesn't exist, it seems. Any other thoughts?

     
    • versat

      versat - 2019-09-18

      The Trac server has moved and https does not work yet. It should work like before sooner or later.
      Meanwhile you can view the ticket here: http://trac.cppcheck.net/ticket/9202

       
  • Steffen

    Steffen - 2019-10-02

    https://trac.cppcheck.net/ticket/9202 was closed but did not fix this particular issue.
    With

    std::array<uint8_t, blockLen>
    

    1.89 and master work fine.

    But with

    std::array<uint8_t, blockLen * 2>
    

    or

    std::array<uint8_t, blockLen + 1>
    

    they do not. The arrayIndexOutOfBounds false positive pops up again.

     
    • versat

      versat - 2019-10-04

      Thanks!
      @amai created a follow up ticket: https://trac.cppcheck.net/ticket/9386

       

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.