Add testcase for previous commit.

This commit is contained in:
Edoardo Prezioso 2011-12-30 18:47:42 +01:00
parent 0d3bf5340d
commit 8f2ad53332
3 changed files with 8 additions and 3 deletions

View File

@ -420,7 +420,7 @@ static bool for_bailout(const Token * const tok1, unsigned int varid)
void CheckBufferOverrun::parse_for_body(const Token *tok, const ArrayInfo &arrayInfo, const std::string &strindex, bool condition_out_of_bounds, unsigned int counter_varid, const std::string &min_counter_value, const std::string &max_counter_value) void CheckBufferOverrun::parse_for_body(const Token *tok, const ArrayInfo &arrayInfo, const std::string &strindex, bool condition_out_of_bounds, unsigned int counter_varid, const std::string &min_counter_value, const std::string &max_counter_value)
{ {
const std::string pattern((arrayInfo.varid() ? std::string("%varid%") : arrayInfo.varname()) + " [ " + strindex + " ]"); const std::string pattern = (arrayInfo.varid() ? std::string("%varid%") : arrayInfo.varname()) + " [ " + strindex + " ]";
for (const Token* tok2 = tok; tok2 && tok2 != tok->link(); tok2 = tok2->next()) { for (const Token* tok2 = tok; tok2 && tok2 != tok->link(); tok2 = tok2->next()) {
// TODO: try to reduce false negatives. This is just a quick fix // TODO: try to reduce false negatives. This is just a quick fix
@ -795,7 +795,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
for (unsigned int i = 0; i < varname.size(); ++i) for (unsigned int i = 0; i < varname.size(); ++i)
varnames += (i == 0 ? "" : " . ") + varname[i]; varnames += (i == 0 ? "" : " . ") + varname[i];
const unsigned char varc(static_cast<unsigned char>(varname.empty() ? 0U : (varname.size() - 1) * 2U)); const unsigned char varc = static_cast<unsigned char>(varname.empty() ? 0U : (varname.size() - 1) * 2U);
if (Token::simpleMatch(tok, "return")) { if (Token::simpleMatch(tok, "return")) {
tok = tok->next(); tok = tok->next();

View File

@ -1241,7 +1241,7 @@ void CheckClass::checkConst()
} }
// get function name // get function name
std::string functionName((func->tokenDef->isName() ? "" : "operator") + func->tokenDef->str()); std::string functionName = (func->tokenDef->isName() ? "" : "operator") + func->tokenDef->str();
if (func->tokenDef->str() == "(") if (func->tokenDef->str() == "(")
functionName += ")"; functionName += ")";

View File

@ -3124,6 +3124,11 @@ private:
ASSERT_EQUALS("\n\n##file 0\n" ASSERT_EQUALS("\n\n##file 0\n"
"1: namespace fruit { using banana ; }\n", "1: namespace fruit { using banana ; }\n",
tokenizeDebugListing(code)); tokenizeDebugListing(code));
//Fix '(debug) found variable with varid 0' in this case
errout.str("");
tokenizeAndStringify(code.c_str());
ASSERT_EQUALS("", errout.str());
} }
void varid44() { void varid44() {