diff options
author | Lei Zhang <thestig@chromium.org> | 2018-03-15 20:58:27 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-03-15 20:58:27 +0000 |
commit | aaf58321fcaefae4bdf2419b5094f810cdcb1a49 (patch) | |
tree | b77cace2326e737ea623ba1a4a0b2844dd482d82 | |
parent | e839a6adb305467759e0d22fe7532a72fe4d8fa7 (diff) | |
download | pdfium-chromium/3325.tar.xz |
M65: Fix bad return value in WideString::Compare().chromium/3325
When comparing L"a" vs L"ab", the return value should be -1 or 1, not 0
or 1. Add a regression test for this case.
BUG=chromium:821454
TBR=rharrison@chromium.org
Change-Id: I38e2d7ca62319b7a62f8d8afeb231b8ed3bd9e86
Reviewed-on: https://pdfium-review.googlesource.com/28570
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
(cherry picked from commit 40c223e4ed41e991f81281ca08b3085e218c52dc)
Reviewed-on: https://pdfium-review.googlesource.com/28650
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
-rw-r--r-- | core/fxcrt/widestring.cpp | 2 | ||||
-rw-r--r-- | core/fxcrt/widestring_unittest.cpp | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/core/fxcrt/widestring.cpp b/core/fxcrt/widestring.cpp index 8d47564e13..7b5bf66fd3 100644 --- a/core/fxcrt/widestring.cpp +++ b/core/fxcrt/widestring.cpp @@ -924,7 +924,7 @@ int WideString::Compare(const WideString& str) const { return result; if (this_len == that_len) return 0; - return this_len < that_len; + return this_len < that_len ? -1 : 1; } int WideString::CompareNoCase(const wchar_t* lpsz) const { diff --git a/core/fxcrt/widestring_unittest.cpp b/core/fxcrt/widestring_unittest.cpp index 2fb9e8c8b4..473d59c491 100644 --- a/core/fxcrt/widestring_unittest.cpp +++ b/core/fxcrt/widestring_unittest.cpp @@ -52,15 +52,18 @@ TEST(WideString, ElementAccess) { TEST(WideString, OperatorLT) { WideString empty; WideString a(L"a"); + WideString ab(L"ab"); WideString abc(L"\x0110qq"); // Comes before despite endianness. WideString def(L"\x1001qq"); // Comes after despite endianness. WideStringView v_empty; WideStringView v_a(L"a"); + WideStringView v_ab(L"ab"); WideStringView v_abc(L"\x0110qq"); WideStringView v_def(L"\x1001qq"); const wchar_t* const c_null = nullptr; const wchar_t* const c_empty = L""; const wchar_t* const c_a = L"a"; + const wchar_t* const c_ab = L"ab"; const wchar_t* const c_abc = L"\x0110qq"; const wchar_t* const c_def = L"\x1001qq"; @@ -142,6 +145,14 @@ TEST(WideString, OperatorLT) { EXPECT_FALSE(def < c_abc); EXPECT_TRUE(abc < v_def); EXPECT_FALSE(def < v_abc); + + EXPECT_TRUE(a < ab); + EXPECT_TRUE(a < c_ab); + EXPECT_TRUE(a < v_ab); + EXPECT_TRUE(c_a < ab); + EXPECT_TRUE(c_a < v_ab); + EXPECT_TRUE(v_a < c_ab); + EXPECT_TRUE(v_a < v_ab); } TEST(WideString, OperatorEQ) { |