简体   繁体   English

如何告诉cppCheck不要将函数视为分配函数?

[英]How can I tell cppCheck to NOT treat a function as an allocation function?

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). 我有一个要使用ctCheck运行的Qt的代码库,我想使其运行得相当干净(抑制或修复大多数错误)。

I have this function addResultLable: 我有此功能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); 我这样称呼:addResultLabel(“ Packets”,TEST_RESULT_OFFSET,nextY); nextY += TEST_RESULT_HEIGHT; nextY + = TEST_RESULT_HEIGHT; m_packets = addResultLabel("0", TEST_RESULT_OFFSET, nextY); m_packets = addResultLabel(“ 0”,TEST_RESULT_OFFSET,nextY);

cppCheck comes up with the (error) Return value of allocation function addResultLabel is not stored. cppCheck附带(error) Return value of allocation function addResultLabel is not stored. addResultLabel的(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. 虽然如此,它不是有关:在QLabel正确到它的父联new QLabel(baseFrame)调用,因此,如果调用者实际上并不重要addResultLabel保持与否。 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. 我想这样做的是告诉cppCheck是addResultLabel其实不是分配的功能,使其停止检查它的调用者。

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. 我已经仔细阅读了手册,虽然可以看到如何添加新的分配函数,但是却看不到如何告诉cppCheck不要将函数视为分配函数。

I am a Cppcheck developer. 我是Cppcheck开发人员。

That is a false positive. 这是一个误报。 It should be fixed in Cppcheck. 它应该在Cppcheck中修复。

I created a ticket about it in the Cppcheck issue tracker: http://trac.cppcheck.net/ticket/6775 我在Cppcheck问题跟踪器中创建了有关它的票证: http ://trac.cppcheck.net/ticket/6775

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM