Fixed false positive va_list_usedBeforeStarted (#7527)

This commit is contained in:
PKEuS 2016-06-02 09:32:45 +02:00
parent 3eb0e9b6c0
commit 9a61559eca
2 changed files with 17 additions and 1 deletions

View File

@ -122,7 +122,7 @@ void CheckVaarg::va_list_usage()
} }
open = nopen; open = nopen;
tok = tok->linkAt(1); tok = tok->linkAt(1);
} else if (Token::Match(tok, "throw|return")) } else if (Token::Match(tok, "throw|return|break"))
exitOnEndOfStatement = true; exitOnEndOfStatement = true;
else if (_tokenizer->isCPP() && tok->str() == "try") { else if (_tokenizer->isCPP() && tok->str() == "try") {
open = false; open = false;

View File

@ -200,6 +200,22 @@ private:
" va_end(v2);\n" " va_end(v2);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #7527
check("void foo(int flag1, int flag2, ...) {\n"
" switch (flag1) {\n"
" default:\n"
" va_list vargs;\n"
" va_start(vargs, flag2);\n"
" if (flag2) {\n"
" va_end(vargs);\n"
" break;\n"
" }\n"
" int data = va_arg(vargs, int);\n"
" va_end(vargs);\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
} }
void va_start_subsequentCalls() { void va_start_subsequentCalls() {