diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-04-12 18:33:55 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-12 18:33:55 +0000 |
commit | 154e18f9a862975abecebe77b8f5fb418418d14c (patch) | |
tree | 18e9381c1a4324abcd98296e1e1714c2f926e006 /core/fxcrt/widestring.h | |
parent | 7f821c11081fe90346823333622253ec7949b583 (diff) | |
download | pdfium-154e18f9a862975abecebe77b8f5fb418418d14c.tar.xz |
Return pdfium::span<wchar_t> from WideString::GetBuffer().
Adds bounds checking "for free", but beware of span outliving
a ReleaseBuffer() call. Scoping as such avoids the possibility
of using an invalid span (and it is flagged as a lifetime issue).
Change-Id: Ica63f4b1429823d0254ec6951aeaeb08160cb93c
Reviewed-on: https://pdfium-review.googlesource.com/30310
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcrt/widestring.h')
-rw-r--r-- | core/fxcrt/widestring.h | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/core/fxcrt/widestring.h b/core/fxcrt/widestring.h index 30a423d9aa..f6c24375a0 100644 --- a/core/fxcrt/widestring.h +++ b/core/fxcrt/widestring.h @@ -17,7 +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 { @@ -163,7 +163,10 @@ class WideString { void TrimRight(const WideStringView& targets); void Reserve(size_t len); - wchar_t* GetBuffer(size_t len); + + // Note: any modification of the string (including ReleaseBuffer()) may + // invalidate the span, which must not outlive its buffer. + pdfium::span<wchar_t> GetBuffer(size_t len); void ReleaseBuffer(size_t len); int GetInteger() const; |