I've got a codebase using Qt that I want run cppCheck on, and I'd like to make it run reasonably clean (suppress or fix most of the errors).
I have this function addResultLable:
QLabel * TestScreen::addResultLabel(const QString& labelText, int x, int y)
{
QLabel *pLabel = new QLabel(baseFrame);
pLabel->setText(labelText);
pLabel->setGeometry(x, y, TEST_RESULT_WIDTH, TEST_RESULT_HEIGHT);
pLabel->setAlignment(Qt::AlignCenter);
return pLabel;
}
And I call it thusly: addResultLabel("Packets", TEST_RESULT_OFFSET, nextY); nextY += TEST_RESULT_HEIGHT; m_packets = addResultLabel("0", TEST_RESULT_OFFSET, nextY);
cppCheck comes up with the (error) Return value of allocation function addResultLabel is not stored.
on that first call.
While true, it's not relevant: the QLabel is linked properly to it's parent in the new QLabel(baseFrame)
call, so it doesn't actually matter if the caller of addResultLabel
keeps it or not. There's a number of these calls, and I don't want to supress at each call site.
What I would like to do is tell cppCheck that addResultLabel
is in fact NOT an allocation function, so that it stops checking it's callers.
I've hunted through the manual, and while I can see how to ADD a new allocation function, I can't see how to tell cppCheck NOT to treat a function as an allocation function.
I am a Cppcheck developer.
That is a false positive. It should be fixed in Cppcheck.
I created a ticket about it in the Cppcheck issue tracker: http://trac.cppcheck.net/ticket/6775