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 --- core/fxcrt/pdfium_span_unittest.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 core/fxcrt/pdfium_span_unittest.cpp (limited to 'core/fxcrt/pdfium_span_unittest.cpp') diff --git a/core/fxcrt/pdfium_span_unittest.cpp b/core/fxcrt/pdfium_span_unittest.cpp new file mode 100644 index 0000000000..177bc4097e --- /dev/null +++ b/core/fxcrt/pdfium_span_unittest.cpp @@ -0,0 +1,30 @@ +// Copyright 2018 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/base/span.h" +#include "third_party/base/stl_util.h" + +// Tests PDFium-modifications to base::span. The name of this file is +// chosen to avoid collisions with base's span_unittest.cc + +TEST(PdfiumSpan, EmptySpan) { + int stuff[] = {1, 2, 3}; + pdfium::span stuff_span(stuff); + pdfium::span empty_first_span = stuff_span.first(0); + pdfium::span empty_last_span = stuff_span.last(0); + pdfium::span empty_sub_span1 = stuff_span.subspan(0, 0); + pdfium::span empty_sub_span2 = stuff_span.subspan(3, 0); + EXPECT_TRUE(empty_first_span.empty()); + EXPECT_TRUE(empty_last_span.empty()); + EXPECT_TRUE(empty_sub_span1.empty()); + EXPECT_TRUE(empty_sub_span2.empty()); +} + +TEST(PdfiumSpan, EmptySpanDeath) { + int stuff[] = {1, 2, 3}; + pdfium::span stuff_span(stuff); + pdfium::span empty_span = stuff_span.last(0); + EXPECT_DEATH(empty_span[0] += 1, ".*"); +} -- cgit v1.2.3