From a6f95eb2eb735e593f201a3ff9daad77c765cce0 Mon Sep 17 00:00:00 2001 From: Bo Xu Date: Wed, 21 Jan 2015 12:17:23 -0800 Subject: Merge to XFA: Simplify UTF16LE_Encode and add unittest. Previously, UTF16LE_Encode take an optional flag to indicate if the returned byte string has trailing zeros. In fact, no where needs the flag to be false. So just get rid of it so callers won't misuse. The bug is found by https://codereview.chromium.org/837723009 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/860973002 --- fpdfsdk/src/fpdfdoc.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'fpdfsdk/src/fpdfdoc.cpp') diff --git a/fpdfsdk/src/fpdfdoc.cpp b/fpdfsdk/src/fpdfdoc.cpp index 23c3c2e713..19b4581829 100644 --- a/fpdfsdk/src/fpdfdoc.cpp +++ b/fpdfsdk/src/fpdfdoc.cpp @@ -55,14 +55,12 @@ DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict, void* return 0; CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); CFX_WideString title = bookmark.GetTitle(); - CFX_ByteString encodedTitle = title.UTF16LE_Encode(FALSE); + CFX_ByteString encodedTitle = title.UTF16LE_Encode(); unsigned long len = encodedTitle.GetLength(); - if (buffer && buflen >= len + 2) { + if (buffer && buflen >= len) { FXSYS_memcpy(buffer, encodedTitle.c_str(), len); - ((FX_BYTE*)buffer)[len] = 0; - ((FX_BYTE*)buffer)[len + 1] = 0; } - return len + 2; + return len; } DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_WIDESTRING title) @@ -296,11 +294,8 @@ DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc, FPDF_BYTESTR // Use UTF-16LE encoding CFX_ByteString encodedText = text.UTF16LE_Encode(); unsigned long len = encodedText.GetLength(); - if (buffer && buflen >= len + 2) { + if (buffer && buflen >= len) { FXSYS_memcpy(buffer, encodedText.c_str(), len); - // use double zero as trailer - ((FX_BYTE*)buffer)[len] = 0; - ((FX_BYTE*)buffer)[len + 1] = 0; } - return len+2; + return len; } -- cgit v1.2.3