Merge pull request #438 from Dmitry-Me/moveDeclarationReorderCheck

Move declaration, run check earlier
This commit is contained in:
amai2012 2014-09-16 20:50:04 +02:00
commit 776e720d8f
2 changed files with 5 additions and 4 deletions

View File

@ -890,9 +890,9 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
}
// Writing data into array..
if (Token::Match(tok, "strcpy|strcat ( %varid% , %str% )", declarationId)) {
if (total_size > 0 && Token::Match(tok, "strcpy|strcat ( %varid% , %str% )", declarationId)) {
const std::size_t len = Token::getStrLength(tok->tokAt(4));
if (total_size > 0 && len >= (unsigned int)total_size) {
if (len >= (unsigned int)total_size) {
bufferOverrunError(tok, arrayInfo.varname());
continue;
}

View File

@ -1092,8 +1092,6 @@ void CheckUnusedVar::checkFunctionVariableUsage()
it != variables.varUsage().end();
++it) {
const Variables::VariableUsage &usage = it->second;
const std::string &varname = usage._var->name();
const Variable* var = symbolDatabase->getVariableFromVarId(it->first);
// variable has been marked as unused so ignore it
if (usage._var->nameToken()->isAttributeUnused() || usage._var->nameToken()->isAttributeUsed())
@ -1105,6 +1103,9 @@ void CheckUnusedVar::checkFunctionVariableUsage()
usage._type == Variables::referenceArray)
continue;
const std::string &varname = usage._var->name();
const Variable* var = symbolDatabase->getVariableFromVarId(it->first);
// variable has had memory allocated for it, but hasn't done
// anything with that memory other than, perhaps, freeing it
if (usage.unused() && !usage._modified && usage._allocateMemory)