From ed1c9bed49a179f8c473c7acec9994a3db865966 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Fri, 11 Sep 2009 23:46:59 +0300 Subject: [PATCH] Fix ticket #632 (Mathlib isInt() identifies "330L" as not int) http://sourceforge.net/apps/trac/cppcheck/ticket/632 --- src/mathlib.cpp | 2 +- test/testmathlib.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/mathlib.cpp b/src/mathlib.cpp index 2e45b8b26..716977586 100644 --- a/src/mathlib.cpp +++ b/src/mathlib.cpp @@ -99,7 +99,7 @@ bool MathLib::isInt(const std::string & s) { Mode = eHex; } - else if (s.find("0", n, 1) != std::string::npos && std::isdigit(s[n+1])) + else if (s.length() > 1 && s[0] == '0' && std::isdigit(s[1])) { Mode = eOctal; } diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index 5dfd6fc52..7efa312fb 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -56,6 +56,7 @@ private: void isint() { + ASSERT_EQUALS(true, MathLib::isInt("0")); ASSERT_EQUALS(true, MathLib::isInt("0xa")); ASSERT_EQUALS(true, MathLib::isInt("0l")); ASSERT_EQUALS(true, MathLib::isInt("0L")); @@ -63,8 +64,10 @@ private: ASSERT_EQUALS(true, MathLib::isInt("0ull")); ASSERT_EQUALS(true, MathLib::isInt("0llu")); ASSERT_EQUALS(true, MathLib::isInt("333L")); - TODO_ASSERT_EQUALS(true, MathLib::isInt("330L")); - TODO_ASSERT_EQUALS(true, MathLib::isInt("330llu")); + ASSERT_EQUALS(true, MathLib::isInt("330L")); + ASSERT_EQUALS(true, MathLib::isInt("330llu")); + ASSERT_EQUALS(true, MathLib::isInt("07")); + ASSERT_EQUALS(true, MathLib::isInt("0123")); ASSERT_EQUALS(false, MathLib::isInt("0.4")); ASSERT_EQUALS(false, MathLib::isInt("2352.3f")); }