summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-04-16 17:28:17 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-16 17:28:17 +0000
commit3d523e3cf89440e2ffc6571b1c687ad5e3f0318f (patch)
treeb546904778c288c9ee9100f8e9da2761a9acc2cb /core/fpdfapi
parentc51196cac2963d94cb0c6434f870fcea83d5c509 (diff)
downloadpdfium-3d523e3cf89440e2ffc6571b1c687ad5e3f0318f.tar.xz
Revert "Return pdfium::span<char> from ByteString::GetBuffer()."
This reverts commit 80a6cbe0a427e155de8555bc867af745d10f9777. Reason for revert: too many abrts in beta branch. TBR: dsinclair@chromium.org Bug: 832557, 832978, 832992, 833062, 833097 Change-Id: I7d511dbb224ddc644be96ea2f3770ad6f73debf5 Reviewed-on: https://pdfium-review.googlesource.com/30792 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/page/cpdf_image.cpp17
-rw-r--r--core/fpdfapi/parser/fpdf_parser_decode.cpp45
-rw-r--r--core/fpdfapi/parser/fpdf_parser_utility.cpp50
3 files changed, 49 insertions, 63 deletions
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index b10134611c..ec826dc5ed 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -200,16 +200,13 @@ void CPDF_Image::SetImage(const RetainPtr<CFX_DIBitmap>& pBitmap) {
pCS->AddNew<CPDF_Name>("DeviceRGB");
pCS->AddNew<CPDF_Number>(1);
ByteString ct;
- {
- // Span's lifetime must end before ReleaseBuffer() below.
- pdfium::span<char> pBuf = ct.GetBuffer(6);
- pBuf[0] = (char)reset_r;
- pBuf[1] = (char)reset_g;
- pBuf[2] = (char)reset_b;
- pBuf[3] = (char)set_r;
- pBuf[4] = (char)set_g;
- pBuf[5] = (char)set_b;
- }
+ char* pBuf = ct.GetBuffer(6);
+ pBuf[0] = (char)reset_r;
+ pBuf[1] = (char)reset_g;
+ pBuf[2] = (char)reset_b;
+ pBuf[3] = (char)set_r;
+ pBuf[4] = (char)set_g;
+ pBuf[5] = (char)set_b;
ct.ReleaseBuffer(6);
pCS->AddNew<CPDF_String>(ct, true);
}
diff --git a/core/fpdfapi/parser/fpdf_parser_decode.cpp b/core/fpdfapi/parser/fpdf_parser_decode.cpp
index 2fdc4daa49..90dca2edcb 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_decode.cpp
@@ -469,22 +469,20 @@ ByteString PDF_EncodeText(const wchar_t* pString, int len) {
if (len == -1)
len = wcslen(pString);
- int i;
ByteString result;
- {
- pdfium::span<char> dest_buf = result.GetBuffer(len);
- for (i = 0; i < len; ++i) {
- int code;
- for (code = 0; code < 256; ++code) {
- if (PDFDocEncoding[code] == pString[i])
- break;
- }
-
- if (code == 256)
+ char* dest_buf1 = result.GetBuffer(len);
+ int i;
+ for (i = 0; i < len; ++i) {
+ int code;
+ for (code = 0; code < 256; ++code) {
+ if (PDFDocEncoding[code] == pString[i])
break;
-
- dest_buf[i] = code;
}
+
+ if (code == 256)
+ break;
+
+ dest_buf1[i] = code;
}
result.ReleaseBuffer(i);
if (i == len)
@@ -495,18 +493,15 @@ ByteString PDF_EncodeText(const wchar_t* pString, int len) {
return result;
}
- size_t dest_index = 0;
- size_t encLen = len * 2 + 2;
- {
- pdfium::span<char> cspan = result.GetBuffer(encLen);
- auto dest_buf = pdfium::make_span(reinterpret_cast<uint8_t*>(cspan.data()),
- cspan.size());
- 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<uint8_t>(pString[j]);
- }
+ int encLen = len * 2 + 2;
+
+ uint8_t* dest_buf2 = reinterpret_cast<uint8_t*>(result.GetBuffer(encLen));
+ dest_buf2[0] = 0xfe;
+ dest_buf2[1] = 0xff;
+ dest_buf2 += 2;
+ for (int j = 0; j < len; ++j) {
+ *dest_buf2++ = pString[j] >> 8;
+ *dest_buf2++ = static_cast<uint8_t>(pString[j]);
}
result.ReleaseBuffer(encLen);
return result;
diff --git a/core/fpdfapi/parser/fpdf_parser_utility.cpp b/core/fpdfapi/parser/fpdf_parser_utility.cpp
index b6b94aa84e..c486a76706 100644
--- a/core/fpdfapi/parser/fpdf_parser_utility.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_utility.cpp
@@ -93,23 +93,20 @@ ByteString PDF_NameDecode(const ByteStringView& bstr) {
if (!bstr.Contains('#'))
return ByteString(bstr);
- size_t src_size = bstr.GetLength();
- size_t out_index = 0;
+ int size = bstr.GetLength();
ByteString result;
- {
- // Span's lifetime must end before ReleaseBuffer() below.
- pdfium::span<char> pDest = result.GetBuffer(src_size);
- for (size_t i = 0; i < src_size; i++) {
- if (bstr[i] == '#' && i < src_size - 2) {
- pDest[out_index++] = FXSYS_HexCharToInt(bstr[i + 1]) * 16 +
- FXSYS_HexCharToInt(bstr[i + 2]);
- i += 2;
- } else {
- pDest[out_index++] = bstr[i];
- }
+ char* pDestStart = result.GetBuffer(size);
+ char* pDest = pDestStart;
+ for (int i = 0; i < size; i++) {
+ if (bstr[i] == '#' && i < size - 2) {
+ *pDest++ = FXSYS_HexCharToInt(bstr[i + 1]) * 16 +
+ FXSYS_HexCharToInt(bstr[i + 2]);
+ i += 2;
+ } else {
+ *pDest++ = bstr[i];
}
}
- result.ReleaseBuffer(out_index);
+ result.ReleaseBuffer(static_cast<size_t>(pDest - pDestStart));
return result;
}
@@ -131,23 +128,20 @@ ByteString PDF_NameEncode(const ByteString& orig) {
return orig;
ByteString res;
- {
- // Span's lifetime must end before ReleaseBuffer() below.
- pdfium::span<char> dest_buf = res.GetBuffer(dest_len);
- dest_len = 0;
- for (i = 0; i < src_len; i++) {
- uint8_t ch = src_buf[i];
- if (ch >= 0x80 || PDFCharIsWhitespace(ch) || ch == '#' ||
- PDFCharIsDelimiter(ch)) {
- dest_buf[dest_len++] = '#';
- FXSYS_IntToTwoHexChars(ch, &dest_buf[dest_len]);
- dest_len += 2;
- continue;
- }
+ char* dest_buf = res.GetBuffer(dest_len);
+ dest_len = 0;
+ for (i = 0; i < src_len; i++) {
+ uint8_t ch = src_buf[i];
+ if (ch >= 0x80 || PDFCharIsWhitespace(ch) || ch == '#' ||
+ PDFCharIsDelimiter(ch)) {
+ dest_buf[dest_len++] = '#';
+ FXSYS_IntToTwoHexChars(ch, dest_buf + dest_len);
+ dest_len += 2;
+ } else {
dest_buf[dest_len++] = ch;
}
- dest_buf[dest_len] = 0;
}
+ dest_buf[dest_len] = 0;
res.ReleaseBuffer(res.GetStringLength());
return res;
}