summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-04-12 19:45:45 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-12 19:45:45 +0000
commit80a6cbe0a427e155de8555bc867af745d10f9777 (patch)
treef5a01546d4081a4c3618350f4b54d13690d30299 /core/fpdfapi/page
parent154e18f9a862975abecebe77b8f5fb418418d14c (diff)
downloadpdfium-80a6cbe0a427e155de8555bc867af745d10f9777.tar.xz
Return pdfium::span<char> from ByteString::GetBuffer().
Get bounds checking "for free". Change-Id: I7b14cacbc7130ced7b5cb1869b82c96ccff8e642 Reviewed-on: https://pdfium-review.googlesource.com/30451 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi/page')
-rw-r--r--core/fpdfapi/page/cpdf_image.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index ec826dc5ed..b10134611c 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -200,13 +200,16 @@ void CPDF_Image::SetImage(const RetainPtr<CFX_DIBitmap>& pBitmap) {
pCS->AddNew<CPDF_Name>("DeviceRGB");
pCS->AddNew<CPDF_Number>(1);
ByteString ct;
- 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;
+ {
+ // 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;
+ }
ct.ReleaseBuffer(6);
pCS->AddNew<CPDF_String>(ct, true);
}