From 319ef06b2f695c7ebc26985d477b71fe8db93d3e Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 2 Jul 2018 19:16:43 +0000 Subject: Add pdfium::Vector2D<>() Many of the FX_Alloc's that have not been converted to std::vector are using FX_Alloc2D and the safe math it performs under the covers. Make an equivalent function for returning a vector to avoid burdening callers with the safe math equivalents. Use it in one place. Change-Id: Ie4a280351b7370b755f2a1928f8b2d84fe007c03 Reviewed-on: https://pdfium-review.googlesource.com/36770 Commit-Queue: Tom Sepez Reviewed-by: Lei Zhang --- third_party/base/stl_util.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'third_party/base/stl_util.h') diff --git a/third_party/base/stl_util.h b/third_party/base/stl_util.h index 6c36ddcda1..5d984dc4cc 100644 --- a/third_party/base/stl_util.h +++ b/third_party/base/stl_util.h @@ -9,8 +9,10 @@ #include #include #include +#include #include "third_party/base/numerics/safe_conversions.h" +#include "third_party/base/numerics/safe_math.h" namespace pdfium { @@ -74,6 +76,14 @@ constexpr const T& clamp(const T& v, const T& lo, const T& hi) { return std::min(std::max(v, lo), hi); } +// Safely allocate a 1-dim vector big enough for |w| by |h| or die. +template +std::vector Vector2D(size_t w, size_t h) { + pdfium::base::CheckedNumeric safe_size = w; + safe_size *= h; + return std::vector(safe_size.ValueOrDie()); +} + } // namespace pdfium #endif // PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ -- cgit v1.2.3