From 80a6cbe0a427e155de8555bc867af745d10f9777 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 12 Apr 2018 19:45:45 +0000 Subject: Return pdfium::span from ByteString::GetBuffer(). Get bounds checking "for free". Change-Id: I7b14cacbc7130ced7b5cb1869b82c96ccff8e642 Reviewed-on: https://pdfium-review.googlesource.com/30451 Commit-Queue: Tom Sepez Reviewed-by: dsinclair --- core/fxcrt/bytestring.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'core/fxcrt/bytestring.h') diff --git a/core/fxcrt/bytestring.h b/core/fxcrt/bytestring.h index 70f10dcaba..c68d2f6991 100644 --- a/core/fxcrt/bytestring.h +++ b/core/fxcrt/bytestring.h @@ -17,6 +17,7 @@ #include "core/fxcrt/string_data_template.h" #include "core/fxcrt/string_view_template.h" #include "third_party/base/optional.h" +#include "third_party/base/span.h" namespace fxcrt { @@ -145,7 +146,10 @@ class ByteString { size_t Delete(size_t index, size_t count = 1); void Reserve(size_t len); - char* GetBuffer(size_t len); + + // Note: any modification of the string (including ReleaseBuffer()) may + // invalidate the span, which must not outlive its buffer. + pdfium::span GetBuffer(size_t len); void ReleaseBuffer(size_t len); ByteString Mid(size_t first, size_t count) const; -- cgit v1.2.3