summaryrefslogtreecommitdiff
path: root/third_party
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-07-02 19:16:43 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-02 19:16:43 +0000
commit319ef06b2f695c7ebc26985d477b71fe8db93d3e (patch)
tree368c89c31a743c3d5e9c7fe1cc4a1eaacb2ee5c0 /third_party
parente353d72449a9298410dc479bf27410d83e56b215 (diff)
downloadpdfium-319ef06b2f695c7ebc26985d477b71fe8db93d3e.tar.xz
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 <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'third_party')
-rw-r--r--third_party/base/stl_util.h10
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_