Library: I had misunderstood const/pure a little so I corrected cfg and code

This commit is contained in:
Daniel Marjamäki 2014-03-14 20:08:34 +01:00
parent 2ba3a36f2c
commit ce1aa1e011
3 changed files with 11 additions and 10 deletions

View File

@ -43,7 +43,7 @@
<function name="strchr"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="1"><not-null/><not-uninit/></arg> </function>
<function name="strcoll"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="1"><not-null/><not-uninit/></arg> <arg nr="2"><not-null/><not-uninit/></arg> </function>
<function name="strcpy"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="1"><not-null/></arg> <arg nr="2"><not-null/><not-uninit/></arg> </function>
<function name="strcmp"> <noreturn>false</noreturn> <const/> <pure/> <leak-ignore/> <arg nr="1"><not-null/><not-uninit/></arg> <arg nr="2"><not-null/><not-uninit/></arg> </function>
<function name="strcmp"> <noreturn>false</noreturn> <pure/> <leak-ignore/> <arg nr="1"><not-null/><not-uninit/></arg> <arg nr="2"><not-null/><not-uninit/></arg> </function>
<function name="strdup"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="1"><not-null/><not-uninit/></arg> </function>
<function name="strlen"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="1"><not-null/><not-uninit/></arg> </function>
<function name="strncat"> <noreturn>false</noreturn> <leak-ignore/> <arg nr="1"><not-null/><not-uninit/></arg> <arg nr="2"><not-null/><not-uninit/></arg> <arg nr="3"><not-bool/><valid>0-</valid></arg> </function>

View File

@ -1370,9 +1370,9 @@ void CheckOther::checkIncorrectLogicOperator()
if (!MathLib::isInt(value2) && !MathLib::isFloat(value2))
continue;
if (isSameExpression(comp1, comp2, _settings->library.functionconst))
if (isSameExpression(comp1, comp2, _settings->library.functionpure))
continue; // same expressions => only report that there are same expressions
if (!isSameExpression(expr1, expr2, _settings->library.functionconst))
if (!isSameExpression(expr1, expr2, _settings->library.functionpure))
continue;
const bool isfloat = astIsFloat(expr1) || MathLib::isFloat(value1) || astIsFloat(expr2) || MathLib::isFloat(value2);
@ -2873,18 +2873,18 @@ void CheckOther::checkDuplicateExpression()
if (tok->isOp() && tok->astOperand1() && !Token::Match(tok, "+|-|*|/|%|=|<<|>>")) {
if (Token::Match(tok, "==|!=|-") && astIsFloat(tok->astOperand1()))
continue;
if (isSameExpression(tok->astOperand1(), tok->astOperand2(), _settings->library.functionconst))
if (isSameExpression(tok->astOperand1(), tok->astOperand2(), _settings->library.functionpure))
duplicateExpressionError(tok, tok, tok->str());
else if (tok->astOperand2() && tok->str() == tok->astOperand1()->str() && isSameExpression(tok->astOperand2(), tok->astOperand1()->astOperand2(), _settings->library.functionconst))
else if (tok->astOperand2() && tok->str() == tok->astOperand1()->str() && isSameExpression(tok->astOperand2(), tok->astOperand1()->astOperand2(), _settings->library.functionpure))
duplicateExpressionError(tok->astOperand2(), tok->astOperand2(), tok->str());
else if (tok->astOperand2()) {
const Token *ast1 = tok->astOperand1();
while (ast1 && tok->str() == ast1->str()) {
if (isSameExpression(ast1->astOperand1(), tok->astOperand2(), _settings->library.functionconst))
if (isSameExpression(ast1->astOperand1(), tok->astOperand2(), _settings->library.functionpure))
duplicateExpressionError(ast1->astOperand1(), tok->astOperand2(), tok->str());
else if (isSameExpression(ast1->astOperand2(), tok->astOperand2(), _settings->library.functionconst))
else if (isSameExpression(ast1->astOperand2(), tok->astOperand2(), _settings->library.functionpure))
duplicateExpressionError(ast1->astOperand2(), tok->astOperand2(), tok->str());
if (!isConstExpression(ast1->astOperand2(), _settings->library.functionconst))
if (!isConstExpression(ast1->astOperand2(), _settings->library.functionpure))
break;
ast1 = ast1->astOperand1();
}

View File

@ -136,9 +136,10 @@ bool Library::load(const tinyxml2::XMLDocument &doc)
_noreturn[name] = (strcmp(functionnode->GetText(), "true") == 0);
else if (strcmp(functionnode->Name(), "pure") == 0)
functionpure.insert(name);
else if (strcmp(functionnode->Name(), "const") == 0)
else if (strcmp(functionnode->Name(), "const") == 0) {
functionconst.insert(name);
else if (strcmp(functionnode->Name(),"leak-ignore")==0)
functionpure.insert(name); // a constant function is pure
} else if (strcmp(functionnode->Name(),"leak-ignore")==0)
leakignore.insert(name);
else if (strcmp(functionnode->Name(), "arg") == 0 && functionnode->Attribute("nr") != nullptr) {
const bool bAnyArg = strcmp(functionnode->Attribute("nr"),"any")==0;