summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/fxcrt/fx_basic_wstring.cpp14
-rw-r--r--core/src/fxcrt/fx_basic_wstring_unittest.cpp12
-rw-r--r--fpdfsdk/src/fpdfdoc_embeddertest.cpp4
-rw-r--r--fpdfsdk/src/fpdftext_embeddertest.cpp41
-rw-r--r--fpdfsdk/src/fpdfview_embeddertest.cpp20
5 files changed, 43 insertions, 48 deletions
diff --git a/core/src/fxcrt/fx_basic_wstring.cpp b/core/src/fxcrt/fx_basic_wstring.cpp
index 220ffbd57d..7ea7e8e112 100644
--- a/core/src/fxcrt/fx_basic_wstring.cpp
+++ b/core/src/fxcrt/fx_basic_wstring.cpp
@@ -287,19 +287,17 @@ CFX_ByteString CFX_WideString::UTF8Encode() const {
return FX_UTF8Encode(*this);
}
CFX_ByteString CFX_WideString::UTF16LE_Encode() const {
- if (m_pData == NULL) {
- return CFX_ByteString(FX_BSTRC("\0\0"));
+ CFX_ByteString result;
+ if (!m_pData) {
+ return result;
}
int len = m_pData->m_nDataLength;
- CFX_ByteString result;
- FX_CHAR* buffer = result.GetBuffer(len * 2 + 2);
- for (int i = 0; i < len; i++) {
+ FX_CHAR* buffer = result.GetBuffer(len * 2);
+ for (int i = 0; i < len; ++i) {
buffer[i * 2] = m_pData->m_String[i] & 0xff;
buffer[i * 2 + 1] = m_pData->m_String[i] >> 8;
}
- buffer[len * 2] = 0;
- buffer[len * 2 + 1] = 0;
- result.ReleaseBuffer(len * 2 + 2);
+ result.ReleaseBuffer(len * 2);
return result;
}
void CFX_WideString::ConvertFrom(const CFX_ByteString& str,
diff --git a/core/src/fxcrt/fx_basic_wstring_unittest.cpp b/core/src/fxcrt/fx_basic_wstring_unittest.cpp
index 74410ddda3..22f42d7985 100644
--- a/core/src/fxcrt/fx_basic_wstring_unittest.cpp
+++ b/core/src/fxcrt/fx_basic_wstring_unittest.cpp
@@ -283,12 +283,12 @@ TEST(fxcrt, WideStringUTF16LE_Encode) {
CFX_WideString ws;
CFX_ByteString bs;
} utf16le_encode_cases[] = {
- {L"", ByteStringLiteral("\0\0")},
- {L"abc", ByteStringLiteral("a\0b\0c\0\0\0")},
- {L"abcdef", ByteStringLiteral("a\0b\0c\0d\0e\0f\0\0\0")},
- {L"abc\0def", ByteStringLiteral("a\0b\0c\0\0\0")},
- {L"\xaabb\xccdd", ByteStringLiteral("\xbb\xaa\xdd\xcc\0\0")},
- {L"\x3132\x6162", ByteStringLiteral("\x32\x31\x62\x61\0\0")},
+ {L"", ByteStringLiteral("")},
+ {L"abc", ByteStringLiteral("a\0b\0c\0")},
+ {L"abcdef", ByteStringLiteral("a\0b\0c\0d\0e\0f\0")},
+ {L"abc\0def", ByteStringLiteral("a\0b\0c\0")},
+ {L"\xaabb\xccdd", ByteStringLiteral("\xbb\xaa\xdd\xcc")},
+ {L"\x3132\x6162", ByteStringLiteral("\x32\x31\x62\x61")},
};
for (size_t i = 0; i < FX_ArraySize(utf16le_encode_cases); ++i) {
diff --git a/fpdfsdk/src/fpdfdoc_embeddertest.cpp b/fpdfsdk/src/fpdfdoc_embeddertest.cpp
index 6435704cb2..221e4da1e8 100644
--- a/fpdfsdk/src/fpdfdoc_embeddertest.cpp
+++ b/fpdfsdk/src/fpdfdoc_embeddertest.cpp
@@ -85,7 +85,7 @@ TEST_F(FPDFDocEmbeddertest, Bookmarks) {
FPDF_BOOKMARK child = FPDFBookmark_GetFirstChild(document(), nullptr);
EXPECT_NE(nullptr, child);
- EXPECT_EQ(34, FPDFBookmark_GetTitle(child, buf, sizeof(buf)));
+ EXPECT_EQ(32, FPDFBookmark_GetTitle(child, buf, sizeof(buf)));
EXPECT_EQ(CFX_WideString(L"A Good Beginning"),
CFX_WideString::FromUTF16LE(buf, 16));
@@ -93,7 +93,7 @@ TEST_F(FPDFDocEmbeddertest, Bookmarks) {
FPDF_BOOKMARK sibling = FPDFBookmark_GetNextSibling(document(), child);
EXPECT_NE(nullptr, sibling);
- EXPECT_EQ(28, FPDFBookmark_GetTitle(sibling, buf, sizeof(buf)));
+ EXPECT_EQ(26, FPDFBookmark_GetTitle(sibling, buf, sizeof(buf)));
EXPECT_EQ(CFX_WideString(L"A Good Ending"),
CFX_WideString::FromUTF16LE(buf, 13));
diff --git a/fpdfsdk/src/fpdftext_embeddertest.cpp b/fpdfsdk/src/fpdftext_embeddertest.cpp
index 6c1ae4ceb8..50eef87341 100644
--- a/fpdfsdk/src/fpdftext_embeddertest.cpp
+++ b/fpdfsdk/src/fpdftext_embeddertest.cpp
@@ -42,8 +42,9 @@ TEST_F(FPDFTextEmbeddertest, Text) {
// Check includes the terminating NUL that is provided.
int num_chars = FPDFText_GetText(textpage, 0, 128, fixed_buffer);
ASSERT_GE(num_chars, 0);
- EXPECT_EQ(sizeof(expected), static_cast<size_t>(num_chars));
- EXPECT_TRUE(check_unsigned_shorts(expected, fixed_buffer, sizeof(expected)));
+ EXPECT_EQ(sizeof(expected) - 1, static_cast<size_t>(num_chars));
+ EXPECT_TRUE(
+ check_unsigned_shorts(expected, fixed_buffer, sizeof(expected) - 1));
// Count does not include the terminating NUL in the string literal.
EXPECT_EQ(sizeof(expected) - 1, FPDFText_CountChars(textpage));
@@ -125,11 +126,10 @@ TEST_F(FPDFTextEmbeddertest, Text) {
EXPECT_EQ(0xbdbd, fixed_buffer[9]);
memset(fixed_buffer, 0xbd, sizeof(fixed_buffer));
- EXPECT_EQ(10, FPDFText_GetBoundedText(textpage, 41.0, 56.0, 82.0, 48.0,
- fixed_buffer, 128));
+ EXPECT_EQ(9, FPDFText_GetBoundedText(textpage, 41.0, 56.0, 82.0, 48.0,
+ fixed_buffer, 128));
EXPECT_TRUE(check_unsigned_shorts(expected + 4, fixed_buffer, 9));
- EXPECT_EQ(0u, fixed_buffer[9]);
- EXPECT_EQ(0xbdbd, fixed_buffer[10]);
+ EXPECT_EQ(0xbdbd, fixed_buffer[9]);
FPDFText_ClosePage(textpage);
UnloadPage(page);
@@ -269,14 +269,13 @@ TEST_F(FPDFTextEmbeddertest, WebLinks) {
// Page contains two HTTP-style URLs.
EXPECT_EQ(2, FPDFLink_CountWebLinks(pagelink));
- // Only a terminating NUL required for bogus links.
- EXPECT_EQ(1, FPDFLink_GetURL(pagelink, 2, nullptr, 0));
- EXPECT_EQ(1, FPDFLink_GetURL(pagelink, 1400, nullptr, 0));
- EXPECT_EQ(1, FPDFLink_GetURL(pagelink, -1, nullptr, 0));
+ EXPECT_EQ(0, FPDFLink_GetURL(pagelink, 2, nullptr, 0));
+ EXPECT_EQ(0, FPDFLink_GetURL(pagelink, 1400, nullptr, 0));
+ EXPECT_EQ(0, FPDFLink_GetURL(pagelink, -1, nullptr, 0));
// Query the number of characters required for each link (incl NUL).
- EXPECT_EQ(25, FPDFLink_GetURL(pagelink, 0, nullptr, 0));
- EXPECT_EQ(26, FPDFLink_GetURL(pagelink, 1, nullptr, 0));
+ EXPECT_EQ(24, FPDFLink_GetURL(pagelink, 0, nullptr, 0));
+ EXPECT_EQ(25, FPDFLink_GetURL(pagelink, 1, nullptr, 0));
static const char expected_url[] = "http://example.com?q=foo";
unsigned short fixed_buffer[128];
@@ -300,21 +299,19 @@ TEST_F(FPDFTextEmbeddertest, WebLinks) {
// Retreive link with exactly-sized buffer.
memset(fixed_buffer, 0xbd, sizeof(fixed_buffer));
- EXPECT_EQ(sizeof(expected_url),
+ EXPECT_EQ(sizeof(expected_url) - 1,
FPDFLink_GetURL(pagelink, 0, fixed_buffer, sizeof(expected_url)));
- EXPECT_TRUE(
- check_unsigned_shorts(expected_url, fixed_buffer, sizeof(expected_url)));
- EXPECT_EQ(0u, fixed_buffer[sizeof(expected_url) - 1]);
- EXPECT_EQ(0xbdbd, fixed_buffer[sizeof(expected_url)]);
+ EXPECT_TRUE(check_unsigned_shorts(expected_url, fixed_buffer,
+ sizeof(expected_url) - 1));
+ EXPECT_EQ(0xbdbd, fixed_buffer[sizeof(expected_url) - 1]);
// Retreive link with ample-sized-buffer.
memset(fixed_buffer, 0xbd, sizeof(fixed_buffer));
- EXPECT_EQ(sizeof(expected_url),
+ EXPECT_EQ(sizeof(expected_url) - 1,
FPDFLink_GetURL(pagelink, 0, fixed_buffer, 128));
- EXPECT_TRUE(
- check_unsigned_shorts(expected_url, fixed_buffer, sizeof(expected_url)));
- EXPECT_EQ(0u, fixed_buffer[sizeof(expected_url) - 1]);
- EXPECT_EQ(0xbdbd, fixed_buffer[sizeof(expected_url)]);
+ EXPECT_TRUE(check_unsigned_shorts(expected_url, fixed_buffer,
+ sizeof(expected_url) - 1));
+ EXPECT_EQ(0xbdbd, fixed_buffer[sizeof(expected_url) - 1]);
// Each link rendered in a single rect in this test page.
EXPECT_EQ(1, FPDFLink_CountRects(pagelink, 0));
diff --git a/fpdfsdk/src/fpdfview_embeddertest.cpp b/fpdfsdk/src/fpdfview_embeddertest.cpp
index 35da9b6caf..2606dc7a0e 100644
--- a/fpdfsdk/src/fpdfview_embeddertest.cpp
+++ b/fpdfsdk/src/fpdfview_embeddertest.cpp
@@ -56,10 +56,10 @@ TEST_F(FPDFViewEmbeddertest, NamedDests) {
buffer_size = 2000000; // Absurdly large, check not used for this case.
dest = FPDF_GetNamedDest(document(), 0, nullptr, &buffer_size);
EXPECT_NE(nullptr, dest);
- EXPECT_EQ(12u, buffer_size);
+ EXPECT_EQ(10u, buffer_size);
// Try to retrieve the first item with too small a buffer.
- buffer_size = 10;
+ buffer_size = 8;
dest = FPDF_GetNamedDest(document(), 0, fixed_buffer, &buffer_size);
EXPECT_NE(nullptr, dest);
EXPECT_EQ(-1, buffer_size);
@@ -69,8 +69,8 @@ TEST_F(FPDFViewEmbeddertest, NamedDests) {
buffer_size = 12;
dest = FPDF_GetNamedDest(document(), 0, fixed_buffer, &buffer_size);
EXPECT_NE(nullptr, dest);
- EXPECT_EQ(12u, buffer_size);
- EXPECT_EQ(std::string("F\0i\0r\0s\0t\0\0\0", 12),
+ EXPECT_EQ(10u, buffer_size);
+ EXPECT_EQ(std::string("F\0i\0r\0s\0t\0", 10),
std::string(fixed_buffer, buffer_size));
// Try to retrieve the second item with ample buffer. Item is taken
@@ -78,8 +78,8 @@ TEST_F(FPDFViewEmbeddertest, NamedDests) {
buffer_size = sizeof(fixed_buffer);
dest = FPDF_GetNamedDest(document(), 1, fixed_buffer, &buffer_size);
EXPECT_NE(nullptr, dest);
- EXPECT_EQ(10u, buffer_size);
- EXPECT_EQ(std::string("N\0e\0x\0t\0\0\0", 10),
+ EXPECT_EQ(8u, buffer_size);
+ EXPECT_EQ(std::string("N\0e\0x\0t\0", 8),
std::string(fixed_buffer, buffer_size));
// Try to retrieve third item with ample buffer. Item is taken
@@ -102,8 +102,8 @@ TEST_F(FPDFViewEmbeddertest, NamedDests) {
buffer_size = sizeof(fixed_buffer);
dest = FPDF_GetNamedDest(document(), 4, fixed_buffer, &buffer_size);
EXPECT_NE(nullptr, dest);
- EXPECT_EQ(30u, buffer_size);
- EXPECT_EQ(std::string("F\0i\0r\0s\0t\0A\0l\0t\0e\0r\0n\0a\0t\0e\0\0\0", 30),
+ EXPECT_EQ(28u, buffer_size);
+ EXPECT_EQ(std::string("F\0i\0r\0s\0t\0A\0l\0t\0e\0r\0n\0a\0t\0e\0", 28),
std::string(fixed_buffer, buffer_size));
// Try to retrieve sixth item with ample buffer. Item istaken from the
@@ -112,8 +112,8 @@ TEST_F(FPDFViewEmbeddertest, NamedDests) {
buffer_size = sizeof(fixed_buffer);
dest = FPDF_GetNamedDest(document(), 5, fixed_buffer, &buffer_size);
EXPECT_NE(nullptr, dest);
- EXPECT_EQ(28u, buffer_size);
- EXPECT_EQ(std::string("L\0a\0s\0t\0A\0l\0t\0e\0r\0n\0a\0t\0e\0\0\0", 28),
+ EXPECT_EQ(26u, buffer_size);
+ EXPECT_EQ(std::string("L\0a\0s\0t\0A\0l\0t\0e\0r\0n\0a\0t\0e\0", 26),
std::string(fixed_buffer, buffer_size));
// Try to retrieve non-existent item with ample buffer.