Bug 398633 - Feature request add tests for qt containers and qobjects
Summary: Feature request add tests for qt containers and qobjects
Status: CONFIRMED
Alias: None
Product: clazy
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: Unassigned bugs mailing-list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-14 18:32 UTC by Mike Harris
Modified: 2018-09-15 20:44 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Harris 2018-09-14 18:32:43 UTC
I have a very simple example that refuses to be flagged by either clang, clang-tidy, clazy, or Krazy2.

QVector<int> myVec;
myVec.push_back(1);
myVec.push_back(2);
int third = myVec.at(3);
int otherThird =myVec[3];
obviously this segfaults because there was never a third element.

The issue is that no single IDE or plugin will flag this. It'll ASSERT in Qt Creator debug build run but that's after it compiles.

there has to be some intellisense like thing in the editor or any static analysis tool that can read Qt Containers.

"Just add the Qt source to your code model" you might say well compiling every single part of Qt takes many days so not an option.

Another example is

QCheckBox *myCheckbox = new QCheckBox();
QListView *myListView = qobject_cast<QListView *>(myCheckBox); //will  equal null
QSize size = myListView->gridSize(); //myListView is null so crashes with segfault again

This leads to deep bugs that aren't flagged with any static analysis tool.
Comment 1 Sergio Martins 2018-09-15 18:15:49 UTC
Your 1st case is difficult to make a generic check for, as there's hundreds of little variations.

Your 2nd case could be done, and we could make the following guideline:

"If you use qobject_cast you should verify the pointer isn't null before dereferencing i. And if you're sure it's not null then you should have used static_cast in the first place"
Comment 2 Mike Harris 2018-09-15 20:44:07 UTC
Can there at least be some form of bounds checking?

I'm not sure what other common standard library like container issues are common but maybe some of the most generic common?