From 3d1cdd0eec554f3cf4ef0bbbf6c3038bc70cd267 Mon Sep 17 00:00:00 2001 From: Ettl Martin Date: Mon, 11 Mar 2013 17:38:03 +0100 Subject: [PATCH] #4645 implemented correct range according manpage of usleep(). --- lib/checkother.cpp | 4 ++-- test/testother.cpp | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index ccff0c21c..025206093 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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()); } } diff --git a/test/testother.cpp b/test/testother.cpp index 3482c4712..405a8a49d 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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);