diff options
Diffstat (limited to 'third_party/base/stl_util.h')
-rw-r--r-- | third_party/base/stl_util.h | 10 |
1 files changed, 10 insertions, 0 deletions
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 <iterator> #include <memory> #include <set> +#include <vector> #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 <typename T> +std::vector<T> Vector2D(size_t w, size_t h) { + pdfium::base::CheckedNumeric<size_t> safe_size = w; + safe_size *= h; + return std::vector<T>(safe_size.ValueOrDie()); +} + } // namespace pdfium #endif // PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ |