I'm stuck with a "conflict" between with AnsiStrings
sprintfmember function and Cppcheck's built-in
sprintf` knowledge.
In cases like this,
const char* name = "X";
int version = 1;
return AnsiString().sprintf("%s.H%02d", name, version); // <-- HERE
I'm getting this warning in the Cppcheck GUI
Id: wrongPrintfScanfArgNum
Summary: sprintf format string requires 0 parameters but 1 is given.
Message: sprintf format string requires 0 parameters but 1 is given.
which shows that Cppcheck is talking about the sprintf
function, but I'm using a member function of the VCL class AnsiString
with the same name.
As to get rid of this false positive, I could use
- an inline suppression:
// cppcheck-suppress wrongPrintfScanfArgNum
- an intermediate variable:
AnsiString result; result.printf(...); return result;
- the
sprintf
function, which means handle the buffer space manually
But all these options work local, and make the code harder to read/maintain.
How can I teach Cppcheck to differentiate between overloaded names?
Edits:
- I wrote override, but meant overloading, I corrected that in the current text.
- added literal initialization of variables, which is important for
name