Properly support "break" in CheckVaarg::va_list_usage() (#7533)
Ran AStyle
This commit is contained in:
parent
321d2aeafb
commit
53e2cabdbb
|
@ -32,7 +32,7 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CWE IDs used:
|
// CWE IDs used:
|
||||||
static const struct CWE CWE398(398U); // Indicator of Poor Code Quality
|
static const struct CWE CWE398(398U); // Indicator of Poor Code Quality
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
|
@ -28,12 +28,12 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CWE IDs used:
|
// CWE IDs used:
|
||||||
static const struct CWE CWE398(398U); // Indicator of Poor Code Quality
|
static const struct CWE CWE398(398U); // Indicator of Poor Code Quality
|
||||||
static const struct CWE CWE597(597U); // Use of Wrong Operator in String Comparison
|
static const struct CWE CWE597(597U); // Use of Wrong Operator in String Comparison
|
||||||
static const struct CWE CWE664(664U); // Improper Control of a Resource Through its Lifetime
|
static const struct CWE CWE664(664U); // Improper Control of a Resource Through its Lifetime
|
||||||
static const struct CWE CWE704(704U); // Incorrect Type Conversion or Cast
|
static const struct CWE CWE704(704U); // Incorrect Type Conversion or Cast
|
||||||
static const struct CWE CWE788(788U); // Access of Memory Location After End of Buffer
|
static const struct CWE CWE788(788U); // Access of Memory Location After End of Buffer
|
||||||
static const struct CWE CWE834(834U); // Excessive Iteration
|
static const struct CWE CWE834(834U); // Excessive Iteration
|
||||||
|
|
||||||
// Error message for bad iterator usage..
|
// Error message for bad iterator usage..
|
||||||
void CheckStl::invalidIteratorError(const Token *tok, const std::string &iteratorName)
|
void CheckStl::invalidIteratorError(const Token *tok, const std::string &iteratorName)
|
||||||
|
|
|
@ -122,9 +122,14 @@ void CheckVaarg::va_list_usage()
|
||||||
}
|
}
|
||||||
open = nopen;
|
open = nopen;
|
||||||
tok = tok->linkAt(1);
|
tok = tok->linkAt(1);
|
||||||
} else if (Token::Match(tok, "throw|return|break"))
|
} else if (Token::Match(tok, "throw|return"))
|
||||||
exitOnEndOfStatement = true;
|
exitOnEndOfStatement = true;
|
||||||
else if (_tokenizer->isCPP() && tok->str() == "try") {
|
else if (tok->str() == "break") {
|
||||||
|
const Scope* scope = tok->scope();
|
||||||
|
while (scope->nestedIn && scope->type != Scope::eFor && scope->type != Scope::eWhile && scope->type != Scope::eDo && scope->type != Scope::eSwitch)
|
||||||
|
scope = scope->nestedIn;
|
||||||
|
tok = scope->classEnd;
|
||||||
|
} else if (_tokenizer->isCPP() && tok->str() == "try") {
|
||||||
open = false;
|
open = false;
|
||||||
break;
|
break;
|
||||||
} else if (!open && tok->varId() == var->declarationId())
|
} else if (!open && tok->varId() == var->declarationId())
|
||||||
|
|
|
@ -216,6 +216,53 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// #7533
|
||||||
|
check("void action_push(int type, ...) {\n"
|
||||||
|
" va_list args;\n"
|
||||||
|
" va_start(args, type);\n"
|
||||||
|
" switch (push_mode) {\n"
|
||||||
|
" case UNDO:\n"
|
||||||
|
" list_add(&act->node, &to_redo);\n"
|
||||||
|
" break;\n"
|
||||||
|
" case REDO:\n"
|
||||||
|
" list_add(&act->node, &to_undo);\n"
|
||||||
|
" break;\n"
|
||||||
|
" }\n"
|
||||||
|
" va_end(args);\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void action_push(int type, ...) {\n"
|
||||||
|
" va_list args;\n"
|
||||||
|
" va_start(args, type);\n"
|
||||||
|
" switch (push_mode) {\n"
|
||||||
|
" case UNDO:\n"
|
||||||
|
" list_add(&act->node, &to_redo);\n"
|
||||||
|
" va_end(args);\n"
|
||||||
|
" break;\n"
|
||||||
|
" case REDO:\n"
|
||||||
|
" list_add(&act->node, &to_undo);\n"
|
||||||
|
" va_end(args);\n"
|
||||||
|
" break;\n"
|
||||||
|
" }\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void action_push(int type, ...) {\n"
|
||||||
|
" va_list args;\n"
|
||||||
|
" va_start(args, type);\n"
|
||||||
|
" switch (push_mode) {\n"
|
||||||
|
" case UNDO:\n"
|
||||||
|
" list_add(&act->node, &to_redo);\n"
|
||||||
|
" break;\n"
|
||||||
|
" case REDO:\n"
|
||||||
|
" list_add(&act->node, &to_undo);\n"
|
||||||
|
" va_end(args);\n"
|
||||||
|
" break;\n"
|
||||||
|
" }\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:13]: (error) va_list 'args' was opened but not closed by va_end().\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void va_start_subsequentCalls() {
|
void va_start_subsequentCalls() {
|
||||||
|
|
Loading…
Reference in New Issue