diff --git a/src/checkbufferoverrun.cpp b/src/checkbufferoverrun.cpp index 954f03af0..ca090e893 100644 --- a/src/checkbufferoverrun.cpp +++ b/src/checkbufferoverrun.cpp @@ -67,6 +67,11 @@ void CheckBufferOverrun::bufferOverrun(const Token *tok) reportError(tok, Severity::possibleError, "bufferOverrun", "Buffer overrun"); } +void CheckBufferOverrun::dangerousStdCin(const Token *tok) +{ + reportError(tok, Severity::possibleError, "dangerousStdCin", "Dangerous usage of std::cin, possible buffer overrun"); +} + void CheckBufferOverrun::strncatUsage(const Token *tok) { reportError(tok, Severity::possibleError, "strncatUsage", "Dangerous usage of strncat. Tip: the 3rd parameter means maximum number of characters to append"); @@ -514,7 +519,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const char *varname[], con // cin.. if (varid > 0 && Token::Match(tok, "cin >> %varid% ;", varid)) { - bufferOverrun(tok); + dangerousStdCin(tok); } // Function call.. diff --git a/src/checkbufferoverrun.h b/src/checkbufferoverrun.h index 1625aeeb8..d3b3a2df8 100644 --- a/src/checkbufferoverrun.h +++ b/src/checkbufferoverrun.h @@ -75,6 +75,7 @@ private: void arrayIndexOutOfBounds(const Token *tok); void arrayIndexOutOfBounds(); void bufferOverrun(const Token *tok); + void dangerousStdCin(const Token *tok); void strncatUsage(const Token *tok); void outOfBounds(const Token *tok, const std::string &what); void sizeArgumentAsChar(const Token *tok); @@ -83,6 +84,7 @@ private: { arrayIndexOutOfBounds(0); bufferOverrun(0); + dangerousStdCin(0); strncatUsage(0); outOfBounds(0, "index"); sizeArgumentAsChar(0); diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index ee57419b4..84fd3ad2f 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -827,7 +827,7 @@ private: " char str[10];\n" " cin >> str;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (possible error) Buffer overrun\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (possible error) Dangerous usage of std::cin, possible buffer overrun\n", errout.str()); }