Menu

containerOutOfBounds False Positive while adding items to a list with CPPCheck 2.6

2021-10-12
2021-10-20
  • Steve Albright

    Steve Albright - 2021-10-12

    The size is increasing along with the loop because items are being appended to it so it looks like the size is being checked too soon.

    error: containerOutOfBounds - Out of bounds access in 'labelList.at', if 'labelList' size is 1 and 'i' is 3

    #include <QHBoxLayout>
    #include <QLabel>
    #include <QList>
    #include <QWidget>
    
    QList<QLabel*> containerOutOfBoundsFalsePositiveExample(QWidget* parent)
    {
       QList<QLabel*> labelList;
       QHBoxLayout* horizontalLayout = new QHBoxLayout(parent);
    
       for(int i = 0; i < 4; ++i)
       {
          labelList.append(new QLabel(parent));
          horizontalLayout->insertWidget(i, labelList.at(i), Qt::AlignCenter);
       }
    
       return labelList;
    }
    
     
  • CHR

    CHR - 2021-10-20

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

     

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.