From c763970de6e749123af76170c16bbc3929058437 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 11 Apr 2018 21:18:38 +0000 Subject: Fix issues with PDFium third_party/base/span.h Remove stray const in operator[] that was introduced when downgrading from C++14 to C++11 syntax. Add missing Get() in first() that was introduced when converting to UnownedPtr. Prevent ASAN from flagging spans where the UnownedPtr points to byte N+1 of a N byte object, and the span is empty. This is legal in C for ordinary pointers so long as the pointer isn't de-referenced, but is not allowed per the rules for UnownedPtr. Change-Id: Ic143c5ef4e37c1cf86f0a3e5408be6e2076a85e2 Reviewed-on: https://pdfium-review.googlesource.com/30212 Commit-Queue: Tom Sepez Reviewed-by: dsinclair --- third_party/base/span.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'third_party') diff --git a/third_party/base/span.h b/third_party/base/span.h index 034c6a35e7..0fb627ba8c 100644 --- a/third_party/base/span.h +++ b/third_party/base/span.h @@ -195,6 +195,7 @@ class span { // [span.cons], span constructors, copy, assignment, and destructor constexpr span() noexcept : data_(nullptr), size_(0) {} constexpr span(T* data, size_t size) noexcept : data_(data), size_(size) {} + // TODO(dcheng): Implement construction from a |begin| and |end| pointer. template constexpr span(T (&array)[N]) noexcept : span(array, N) {} @@ -215,12 +216,18 @@ class span { template > constexpr span(const span& other) : span(other.data(), other.size()) {} span& operator=(const span& other) noexcept = default; - ~span() noexcept = default; + ~span() noexcept { + if (!size_) { + // Empty spans might point to byte N+1 of a N-byte object, legal for + // C pointers but not UnownedPtrs. + data_.ReleaseBadPointer(); + } + } // [span.sub], span subviews const span first(size_t count) const { CHECK(count <= size_); - return span(data_, count); + return span(data_.Get(), count); } const span last(size_t count) const { @@ -240,7 +247,7 @@ class span { constexpr bool empty() const noexcept { return size_ == 0; } // [span.elem], span element access - const T& operator[](size_t index) const noexcept { + T& operator[](size_t index) const noexcept { CHECK(index < size_); return data_.Get()[index]; } -- cgit v1.2.3