astyle formatting, use isEnabled("warning") instead of isEnabled("style")
This commit is contained in:
parent
1409461e4f
commit
9ff204f8bc
|
@ -524,7 +524,8 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
||||||
|
|
||||||
bool _continue = false;
|
bool _continue = false;
|
||||||
std::string width;
|
std::string width;
|
||||||
unsigned int parameterPosition = 0; bool hasParameterPosition = false;
|
unsigned int parameterPosition = 0;
|
||||||
|
bool hasParameterPosition = false;
|
||||||
while (i != formatString.end() && *i != ']' && !std::isalpha(*i)) {
|
while (i != formatString.end() && *i != ']' && !std::isalpha(*i)) {
|
||||||
if (*i == '*') {
|
if (*i == '*') {
|
||||||
if (scan)
|
if (scan)
|
||||||
|
@ -550,10 +551,10 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
||||||
|
|
||||||
if (scan || *i != 'm') { // %m is a non-standard extension that requires no parameter on print functions.
|
if (scan || *i != 'm') { // %m is a non-standard extension that requires no parameter on print functions.
|
||||||
++numFormat;
|
++numFormat;
|
||||||
|
|
||||||
// Handle parameter positions (POSIX extension) - Ticket #4900
|
// Handle parameter positions (POSIX extension) - Ticket #4900
|
||||||
if(hasParameterPosition) {
|
if (hasParameterPosition) {
|
||||||
if(parameterPositionsUsed.find(parameterPosition) == parameterPositionsUsed.end())
|
if (parameterPositionsUsed.find(parameterPosition) == parameterPositionsUsed.end())
|
||||||
parameterPositionsUsed.insert(parameterPosition);
|
parameterPositionsUsed.insert(parameterPosition);
|
||||||
else // Parameter already referenced, hence don't consider it a new format
|
else // Parameter already referenced, hence don't consider it a new format
|
||||||
--numFormat;
|
--numFormat;
|
||||||
|
@ -733,10 +734,10 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
||||||
numFunction++;
|
numFunction++;
|
||||||
argListTok2 = argListTok2->nextArgument(); // Find next argument
|
argListTok2 = argListTok2->nextArgument(); // Find next argument
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that all parameter positions reference an actual parameter
|
// Check that all parameter positions reference an actual parameter
|
||||||
for(std::set<unsigned int>::const_iterator it = parameterPositionsUsed.begin() ; it != parameterPositionsUsed.end() ; ++it) {
|
for (std::set<unsigned int>::const_iterator it = parameterPositionsUsed.begin() ; it != parameterPositionsUsed.end() ; ++it) {
|
||||||
if((*it == 0) || (*it > numFormat))
|
if ((*it == 0) || (*it > numFormat))
|
||||||
wrongPrintfScanfPosixParameterPositionError(tok, tok->str(), *it, numFormat);
|
wrongPrintfScanfPosixParameterPositionError(tok, tok->str(), *it, numFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -769,13 +770,13 @@ void CheckIO::wrongPrintfScanfArgumentsError(const Token* tok,
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckIO::wrongPrintfScanfPosixParameterPositionError(const Token* tok, const std::string& functionName,
|
void CheckIO::wrongPrintfScanfPosixParameterPositionError(const Token* tok, const std::string& functionName,
|
||||||
unsigned int index, unsigned int numFunction)
|
unsigned int index, unsigned int numFunction)
|
||||||
{
|
{
|
||||||
if (!_settings->isEnabled("style"))
|
if (!_settings->isEnabled("warning"))
|
||||||
return;
|
return;
|
||||||
std::ostringstream errmsg;
|
std::ostringstream errmsg;
|
||||||
errmsg << functionName << ": ";
|
errmsg << functionName << ": ";
|
||||||
if(index == 0) {
|
if (index == 0) {
|
||||||
errmsg << "parameter positions start at 1, not 0";
|
errmsg << "parameter positions start at 1, not 0";
|
||||||
} else {
|
} else {
|
||||||
errmsg << "referencing parameter " << index << " while " << numFunction << " arguments given";
|
errmsg << "referencing parameter " << index << " while " << numFunction << " arguments given";
|
||||||
|
|
|
@ -83,7 +83,7 @@ private:
|
||||||
unsigned int numFormat,
|
unsigned int numFormat,
|
||||||
unsigned int numFunction);
|
unsigned int numFunction);
|
||||||
void wrongPrintfScanfPosixParameterPositionError(const Token* tok, const std::string& functionName,
|
void wrongPrintfScanfPosixParameterPositionError(const Token* tok, const std::string& functionName,
|
||||||
unsigned int index, unsigned int numFunction);
|
unsigned int index, unsigned int numFunction);
|
||||||
void invalidScanfArgTypeError(const Token* tok, const std::string &functionName, unsigned int numFormat);
|
void invalidScanfArgTypeError(const Token* tok, const std::string &functionName, unsigned int numFormat);
|
||||||
void invalidPrintfArgTypeError_s(const Token* tok, unsigned int numFormat);
|
void invalidPrintfArgTypeError_s(const Token* tok, unsigned int numFormat);
|
||||||
void invalidPrintfArgTypeError_n(const Token* tok, unsigned int numFormat);
|
void invalidPrintfArgTypeError_n(const Token* tok, unsigned int numFormat);
|
||||||
|
|
|
@ -786,7 +786,7 @@ private:
|
||||||
" int bar;"
|
" int bar;"
|
||||||
" printf(\"%1$d\", 1);"
|
" printf(\"%1$d\", 1);"
|
||||||
" printf(\"%1$d, %d, %1$d\", 1, 2);"
|
" printf(\"%1$d, %d, %1$d\", 1, 2);"
|
||||||
" scanf(\"%1$d\", &bar);"
|
" scanf(\"%1$d\", &bar);"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue