class AsyncImageRenderThread : public QThread
{
public:
using pointerToRenderFunction =
std::function<void(asyncimagerenderthread &callbackobject)="">;
virtual void run() override;
std::atomic_bool m_loopAbort = false;
const pointerToRenderFunction m_renderFunction;
};</void(asyncimagerenderthread>
endif // ASYNCIMAGERENDERTHREAD_H
Source:
include "asyncimagerenderthread.h"
void AsyncImageRenderThread::run()
{
while (true) {
if (m_loopAbort) {
return;
}
m_renderFunction(*this);
if (m_loopAbort) {
return;
}
// In original code, here more commands.
}
}
This produces a false positive "Iterating over container 'candidates' that
is always empty. (CWE-398)", wrongly complaining about the double call of
if(m_loopAbort). Indeed, m_renderFunction(*this); can change the state of
m_loopAbort.
Consider the following code:
Header:
ifndef ASYNCIMAGERENDERTHREAD_H
define ASYNCIMAGERENDERTHREAD_H
include <qthread.h></qthread.h>
class AsyncImageRenderThread : public QThread
{
public:
using pointerToRenderFunction =
std::function<void(asyncimagerenderthread &callbackobject)="">;
virtual void run() override;
std::atomic_bool m_loopAbort = false;
const pointerToRenderFunction m_renderFunction;
};</void(asyncimagerenderthread>
endif // ASYNCIMAGERENDERTHREAD_H
Source:
include "asyncimagerenderthread.h"
void AsyncImageRenderThread::run()
{
while (true) {
if (m_loopAbort) {
return;
}
m_renderFunction(*this);
if (m_loopAbort) {
return;
}
// In original code, here more commands.
}
}
This produces a false positive "Iterating over container 'candidates' that
is always empty. (CWE-398)", wrongly complaining about the double call of
if(m_loopAbort). Indeed, m_renderFunction(*this); can change the state of
m_loopAbort.
Best regards
Lukas Sommer
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11478