Merge pull request #559 from Dmitry-Me/omitUnneededActions2

Omit unnecessary operations
This commit is contained in:
amai2012 2015-03-19 19:03:47 +01:00
commit 4086127144
1 changed files with 6 additions and 4 deletions

View File

@ -1736,13 +1736,15 @@ Check::FileInfo* CheckBufferOverrun::getFileInfo(const Tokenizer *tokenizer, con
tok->next()->astOperand2()) { tok->next()->astOperand2()) {
const ValueFlow::Value *value = tok->next()->astOperand2()->getMaxValue(false); const ValueFlow::Value *value = tok->next()->astOperand2()->getMaxValue(false);
if (value && value->intvalue > 0) { if (value && value->intvalue > 0) {
const int arrayIndex = value->intvalue;
std::map<std::string, struct MyFileInfo::ArrayUsage>::iterator it = fileInfo->arrayUsage.find(tok->str());
if (it != fileInfo->arrayUsage.end() && it->second.index >= arrayIndex)
continue;
struct MyFileInfo::ArrayUsage arrayUsage; struct MyFileInfo::ArrayUsage arrayUsage;
arrayUsage.index = value->intvalue; arrayUsage.index = arrayIndex;
arrayUsage.fileName = tokenizer->list.file(tok); arrayUsage.fileName = tokenizer->list.file(tok);
arrayUsage.linenr = tok->linenr(); arrayUsage.linenr = tok->linenr();
std::map<std::string, struct MyFileInfo::ArrayUsage>::iterator it = fileInfo->arrayUsage.find(tok->str()); fileInfo->arrayUsage[tok->str()] = arrayUsage;
if (it == fileInfo->arrayUsage.end() || it->second.index < arrayUsage.index)
fileInfo->arrayUsage[tok->str()] = arrayUsage;
} }
} }
} }