From 042c4f09e34157522692d6f99f5c51bc04e8f27a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 20 Sep 2013 14:05:43 +0300 Subject: fix possible issue in string comparison --- src/utils/stringutils.cpp | 2 +- src/utils/stringutils_unittest.cc | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 680d8e44d..18a3fba12 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -129,7 +129,7 @@ int compareStrI(const std::string &a, const std::string &b) std::string::const_iterator itB = b.begin(); const std::string::const_iterator endB = b.end(); - for (; itA < endA, itB < endB; ++itA, ++itB) + for (; itA < endA && itB < endB; ++itA, ++itB) { const int comp = tolower(*itA) - tolower(*itB); if (comp) diff --git a/src/utils/stringutils_unittest.cc b/src/utils/stringutils_unittest.cc index 8f28f5c10..06ddaefd4 100644 --- a/src/utils/stringutils_unittest.cc +++ b/src/utils/stringutils_unittest.cc @@ -144,7 +144,11 @@ TEST(stringuntils, compareStrI1) EXPECT_TRUE(compareStrI(str1, str2) < 0); str1 = "test"; - str2 = "aest1"; + str2 = "aest1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + EXPECT_TRUE(compareStrI(str1, str2) > 0); + + str1 = "testaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + str2 = "testaa"; EXPECT_TRUE(compareStrI(str1, str2) > 0); } -- cgit v1.2.3-70-g09d2