From 8ba9749e2f39287137a96ec5ceff2ac694566f48 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 10 Aug 2018 22:38:53 +0000 Subject: Remove unused form of PDF_EncodeText(). Perform indexing via WideString::operator[] which will at least assert bounds, if not enforce them. Change-Id: I7b03cfd718c4acd642af910c2ca06f86d178e5fd Reviewed-on: https://pdfium-review.googlesource.com/39873 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- core/fpdfapi/parser/fpdf_parser_decode.cpp | 21 +++++++-------------- core/fpdfapi/parser/fpdf_parser_decode.h | 1 - 2 files changed, 7 insertions(+), 15 deletions(-) (limited to 'core/fpdfapi/parser') diff --git a/core/fpdfapi/parser/fpdf_parser_decode.cpp b/core/fpdfapi/parser/fpdf_parser_decode.cpp index 9ccca121ad..928d650103 100644 --- a/core/fpdfapi/parser/fpdf_parser_decode.cpp +++ b/core/fpdfapi/parser/fpdf_parser_decode.cpp @@ -467,21 +467,18 @@ WideString PDF_DecodeText(const ByteString& bstr) { bstr.GetLength()); } -ByteString PDF_EncodeText(const wchar_t* pString, int len) { - if (len == -1) - len = wcslen(pString); - - int i; +ByteString PDF_EncodeText(const WideString& str) { + size_t i = 0; + size_t len = str.GetLength(); ByteString result; { pdfium::span dest_buf = result.GetBuffer(len); for (i = 0; i < len; ++i) { int code; for (code = 0; code < 256; ++code) { - if (PDFDocEncoding[code] == pString[i]) + if (PDFDocEncoding[code] == str[i]) break; } - if (code == 256) break; @@ -504,19 +501,15 @@ ByteString PDF_EncodeText(const wchar_t* pString, int len) { pdfium::as_writable_bytes(result.GetBuffer(encLen)); dest_buf[dest_index++] = 0xfe; dest_buf[dest_index++] = 0xff; - for (int j = 0; j < len; ++j) { - dest_buf[dest_index++] = pString[j] >> 8; - dest_buf[dest_index++] = static_cast(pString[j]); + for (size_t j = 0; j < len; ++j) { + dest_buf[dest_index++] = str[j] >> 8; + dest_buf[dest_index++] = static_cast(str[j]); } } result.ReleaseBuffer(encLen); return result; } -ByteString PDF_EncodeText(const WideString& str) { - return PDF_EncodeText(str.c_str(), str.GetLength()); -} - ByteString PDF_EncodeString(const ByteString& src, bool bHex) { std::ostringstream result; int srclen = src.GetLength(); diff --git a/core/fpdfapi/parser/fpdf_parser_decode.h b/core/fpdfapi/parser/fpdf_parser_decode.h index 328fd474c6..652299992a 100644 --- a/core/fpdfapi/parser/fpdf_parser_decode.h +++ b/core/fpdfapi/parser/fpdf_parser_decode.h @@ -21,7 +21,6 @@ extern const uint16_t PDFDocEncoding[256]; ByteString PDF_EncodeString(const ByteString& src, bool bHex); WideString PDF_DecodeText(const uint8_t* pData, uint32_t size); WideString PDF_DecodeText(const ByteString& bstr); -ByteString PDF_EncodeText(const wchar_t* pString, int len); ByteString PDF_EncodeText(const WideString& str); bool FlateEncode(const uint8_t* src_buf, -- cgit v1.2.3