#4645 implemented correct range according manpage of usleep().

This commit is contained in:
Ettl Martin 2013-03-11 17:38:03 +01:00
parent dde51f73ff
commit 3d1cdd0eec
2 changed files with 13 additions and 3 deletions

View File

@ -645,7 +645,7 @@ void CheckOther::checkPipeParameterSizeError(const Token *tok, const std::string
}
//-----------------------------------------------------------------------------
// check usleep(), which is allowed to be called with in a range of [0,1000000]
// check usleep(), which is allowed to be called with in a range of [0,999999]
//
// Reference:
// - http://man7.org/linux/man-pages/man3/usleep.3.html
@ -663,7 +663,7 @@ void CheckOther::checkSleepTimeInterval()
if (Token::Match(tok, "usleep ( %num% )")) {
const Token * const numTok = tok->tokAt(2);
MathLib::bigint value = MathLib::toLongNumber(numTok->str());
if (value > 1000000) {
if (value > 999999) { // less than 1 million
checkSleepTimeError(numTok, numTok->str());
}
}

View File

@ -7335,12 +7335,22 @@ private:
}
void checkSleepTimeIntervall() {
// check usleep(), which is allowed to be called with in a range of [0,1000000]
// check usleep(), which is allowed to be called with in a range of [0,999999]
check("void f(){\n"
"usleep(10000);\n"
"}",NULL,false,false,true);
ASSERT_EQUALS("", errout.str());
check("void f(){\n"
"usleep(999999);\n"
"}",NULL,false,false,true);
ASSERT_EQUALS("", errout.str());
check("void f(){\n"
"usleep(1000000);\n"
"}",NULL,false,false,true);
ASSERT_EQUALS("[test.cpp:2]: (error) The argument of usleep must be less than 1000000.\n", errout.str());
check("void f(){\n"
"usleep(1000001);\n"
"}",NULL,false,false,true);