Use WideStringFromFPDFWideString() in more places.
Also rename CFXByteStringFromFPDFWideString() to
ByteStringFromFPDFWideString(), and implement it using
WideStringFromFPDFWideString().
Change-Id: I323bf69f90cdec78bbee562b9aed6513599c9e33
Reviewed-on: https://pdfium-review.googlesource.com/c/47692
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/fpdf_attachment.cpp b/fpdfsdk/fpdf_attachment.cpp
index de7389d..3db89a8 100644
--- a/fpdfsdk/fpdf_attachment.cpp
+++ b/fpdfsdk/fpdf_attachment.cpp
@@ -59,15 +59,17 @@
FPDF_EXPORT FPDF_ATTACHMENT FPDF_CALLCONV
FPDFDoc_AddAttachment(FPDF_DOCUMENT document, FPDF_WIDESTRING name) {
CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
- WideString wsName =
- WideString::FromUTF16LE(name, WideString::WStringLength(name));
- if (!pDoc || wsName.IsEmpty())
+ if (!pDoc)
return nullptr;
CPDF_Dictionary* pRoot = pDoc->GetRoot();
if (!pRoot)
return nullptr;
+ WideString wsName = WideStringFromFPDFWideString(name);
+ if (wsName.IsEmpty())
+ return nullptr;
+
// Retrieve the document's Names dictionary; create it if missing.
CPDF_Dictionary* pNames = pRoot->GetDictFor("Names");
if (!pNames) {
@@ -170,7 +172,7 @@
return false;
ByteString bsKey = key;
- ByteString bsValue = CFXByteStringFromFPDFWideString(value);
+ ByteString bsValue = ByteStringFromFPDFWideString(value);
bool bEncodedAsHex = bsKey == kChecksumKey;
if (bEncodedAsHex)
bsValue = CFXByteStringHexDecode(bsValue);