#6141 FP: Unknown type is assumed to have size 0.

This commit is contained in:
Alexander Mai 2014-09-27 21:51:11 +02:00
parent 210294443e
commit ccd80e3407
2 changed files with 12 additions and 1 deletions

View File

@ -666,7 +666,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
const std::string snprintfPattern = declarationId > 0 ? std::string("snprintf ( %varid% , %num% ,") : ("snprintf ( " + varnames + " , %num% ,"); const std::string snprintfPattern = declarationId > 0 ? std::string("snprintf ( %varid% , %num% ,") : ("snprintf ( " + varnames + " , %num% ,");
if (Token::Match(tok, snprintfPattern.c_str(), declarationId)) { if (Token::Match(tok, snprintfPattern.c_str(), declarationId)) {
const MathLib::bigint n = MathLib::toLongNumber(tok->strAt(4 + varcount)); const MathLib::bigint n = MathLib::toLongNumber(tok->strAt(4 + varcount));
if (n > total_size) if ((n > total_size) && total_size > 0)
outOfBoundsError(tok->tokAt(4 + varcount), "snprintf size", true, n, total_size); outOfBoundsError(tok->tokAt(4 + varcount), "snprintf size", true, n, total_size);
} }

View File

@ -3176,6 +3176,17 @@ private:
" snprintf(pString, 1024, \"ab\");\n" " snprintf(pString, 1024, \"ab\");\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #6141 FP: Unknown type is assumed to have size 0
check("typedef struct {\n"
" CHAR s[42];\n"
"} sct_t;\n"
"void foo() {\n"
" sct_t p;\n"
" snprintf(p.s, 42, \"abcdef\");\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void strncat1() { void strncat1() {