diff options
Diffstat (limited to 'extern/draco/draco/src/draco/core/vector_d.h')
-rw-r--r-- | extern/draco/draco/src/draco/core/vector_d.h | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/extern/draco/draco/src/draco/core/vector_d.h b/extern/draco/draco/src/draco/core/vector_d.h index bed97304feb..a0ec2dedf2e 100644 --- a/extern/draco/draco/src/draco/core/vector_d.h +++ b/extern/draco/draco/src/draco/core/vector_d.h @@ -20,6 +20,7 @@ #include <algorithm> #include <array> #include <cmath> +#include <limits> #include "draco/core/macros.h" @@ -33,7 +34,7 @@ class VectorD { typedef ScalarT Scalar; typedef VectorD<Scalar, dimension_t> Self; - // TODO(hemmer): Deprecate. + // TODO(b/199760123): Deprecate. typedef ScalarT CoefficientType; VectorD() { @@ -44,7 +45,7 @@ class VectorD { // The following constructor does not compile in opt mode, which for now led // to the constructors further down, which is not ideal. - // TODO(hemmer): fix constructor below and remove others. + // TODO(b/199760123): Fix constructor below and remove others. // template <typename... Args> // explicit VectorD(Args... args) : v_({args...}) {} @@ -110,7 +111,7 @@ class VectorD { Scalar &operator[](int i) { return v_[i]; } const Scalar &operator[](int i) const { return v_[i]; } - // TODO(hemmer): remove. + // TODO(b/199760123): Remove. // Similar to interface of Eigen library. Scalar &operator()(int i) { return v_[i]; } const Scalar &operator()(int i) const { return v_[i]; } @@ -236,7 +237,12 @@ class VectorD { Scalar AbsSum() const { Scalar result(0); for (int i = 0; i < dimension; ++i) { - result += std::abs(v_[i]); + Scalar next_value = std::abs(v_[i]); + if (result > std::numeric_limits<Scalar>::max() - next_value) { + // Return the max if adding would have caused an overflow. + return std::numeric_limits<Scalar>::max(); + } + result += next_value; } return result; } |