summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzmiao <miao.zhao@mapbox.com>2020-04-02 22:49:54 +0300
committerzmiao <miao.zhao@mapbox.com>2020-04-03 12:32:58 +0300
commit670f99b2295005d5a9e051655ee00130c09101e0 (patch)
tree4f808b51cef29144879948bfeba9c28ba3595003
parenteb2ff5b9fbcbd34c61caa4abf65a5275aefff5ab (diff)
downloadqtlocation-mapboxgl-670f99b2295005d5a9e051655ee00130c09101e0.tar.gz
[build] Fix division by zero runtime error
-rw-r--r--src/mbgl/geometry/line_atlas.cpp6
-rw-r--r--src/mbgl/renderer/layers/render_line_layer.cpp6
-rw-r--r--src/mbgl/sprite/sprite_parser.cpp5
-rw-r--r--src/mbgl/style/expression/compound_expression.cpp9
4 files changed, 21 insertions, 5 deletions
diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp
index 0739d18685..2042195b6c 100644
--- a/src/mbgl/geometry/line_atlas.cpp
+++ b/src/mbgl/geometry/line_atlas.cpp
@@ -60,7 +60,11 @@ void addRoundDash(
DashRange range = ranges[currIndex];
for (uint32_t x = 0; x < image.size.width; ++x) {
- if (x / range.right > 1.0f && ++currIndex < ranges.size()) {
+ if (range.right == 0) {
+ if (x != 0 && ++currIndex < ranges.size()) {
+ range = ranges[currIndex];
+ }
+ } else if (x / range.right > 1.0f && ++currIndex < ranges.size()) {
range = ranges[currIndex];
}
diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp
index af5c288704..249248e666 100644
--- a/src/mbgl/renderer/layers/render_line_layer.cpp
+++ b/src/mbgl/renderer/layers/render_line_layer.cpp
@@ -242,7 +242,11 @@ GeometryCollection offsetLine(const GeometryCollection& rings, double offset) {
Point<double> extrude = util::unit(aToB + bToC);
const double cosHalfAngle = extrude.x * bToC.x + extrude.y * bToC.y;
- extrude *= (1.0 / cosHalfAngle);
+ if (cosHalfAngle == 0) {
+ extrude = zero;
+ } else {
+ extrude *= (1.0 / cosHalfAngle);
+ }
newRing.emplace_back(convertPoint<int16_t>(extrude * offset) + p);
}
diff --git a/src/mbgl/sprite/sprite_parser.cpp b/src/mbgl/sprite/sprite_parser.cpp
index c51e5e1b57..997e363e50 100644
--- a/src/mbgl/sprite/sprite_parser.cpp
+++ b/src/mbgl/sprite/sprite_parser.cpp
@@ -27,8 +27,9 @@ std::unique_ptr<style::Image> createStyleImage(const std::string& id,
style::ImageStretches&& stretchY,
const optional<style::ImageContent>& content) {
// Disallow invalid parameter configurations.
- if (width <= 0 || height <= 0 || width > 1024 || height > 1024 || ratio <= 0 || ratio > 10 || srcX < 0 || srcY < 0 ||
- srcX >= static_cast<int32_t>(image.size.width) || srcY >= static_cast<int32_t>(image.size.height) || srcX + width > static_cast<int32_t>(image.size.width) ||
+ if (width <= 0 || height <= 0 || width > 1024 || height > 1024 || ratio <= 0 || ratio > 10 || srcX < 0 ||
+ srcY < 0 || srcX >= static_cast<int32_t>(image.size.width) || srcY >= static_cast<int32_t>(image.size.height) ||
+ srcX + width > static_cast<int32_t>(image.size.width) ||
srcY + height > static_cast<int32_t>(image.size.height)) {
Log::Error(Event::Sprite,
"Can't create image with invalid metrics: %dx%d@%d,%d in %ux%u@%sx sprite",
diff --git a/src/mbgl/style/expression/compound_expression.cpp b/src/mbgl/style/expression/compound_expression.cpp
index 2477fe7917..d1722b071f 100644
--- a/src/mbgl/style/expression/compound_expression.cpp
+++ b/src/mbgl/style/expression/compound_expression.cpp
@@ -15,6 +15,7 @@
#include <mapbox/eternal.hpp>
#include <cmath>
+#include <limits>
namespace mbgl {
namespace style {
@@ -498,7 +499,13 @@ const auto& multiplyCompoundExpression() {
}
const auto& divideCompoundExpression() {
- static auto signature = detail::makeSignature("/", [](double a, double b) -> Result<double> { return a / b; });
+ static auto signature = detail::makeSignature("/", [](double a, double b) -> Result<double> {
+ if (b == 0) {
+ if (a == 0) return std::numeric_limits<double>::quiet_NaN();
+ return std::numeric_limits<double>::infinity();
+ }
+ return a / b;
+ });
return signature;
}