summaryrefslogtreecommitdiff
path: root/include/mbgl/style
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-11-30 10:17:47 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-12-01 09:00:06 -0800
commit7d16824fda7086fbeb0a1deae3fc0abdf0c4832d (patch)
tree11c35642db033c685e78c8b45d28af68a5f3d30b /include/mbgl/style
parent54c557d982c92caefd53a68e2f72bba822101c2c (diff)
downloadqtlocation-mapboxgl-7d16824fda7086fbeb0a1deae3fc0abdf0c4832d.tar.gz
[core] Functions must have at least one stop
This is already enforced by the style validator in mapbox-gl-style-spec. Enforce it here too.
Diffstat (limited to 'include/mbgl/style')
-rw-r--r--include/mbgl/style/conversion/function.hpp4
-rw-r--r--include/mbgl/style/function.hpp6
2 files changed, 8 insertions, 2 deletions
diff --git a/include/mbgl/style/conversion/function.hpp b/include/mbgl/style/conversion/function.hpp
index f14b5089be..6a0b67618f 100644
--- a/include/mbgl/style/conversion/function.hpp
+++ b/include/mbgl/style/conversion/function.hpp
@@ -25,6 +25,10 @@ struct Converter<Function<T>> {
return Error { "function stops must be an array" };
}
+ if (arrayLength(*stopsValue) == 0) {
+ return Error { "function must have at least one stop" };
+ }
+
std::vector<std::pair<float, T>> stops;
for (std::size_t i = 0; i < arrayLength(*stopsValue); ++i) {
const auto& stopValue = arrayMember(*stopsValue, i);
diff --git a/include/mbgl/style/function.hpp b/include/mbgl/style/function.hpp
index 97e880b280..3aefba6600 100644
--- a/include/mbgl/style/function.hpp
+++ b/include/mbgl/style/function.hpp
@@ -12,8 +12,10 @@ public:
using Stop = std::pair<float, T>;
using Stops = std::vector<Stop>;
- explicit Function(Stops stops_, float base_)
- : base(base_), stops(std::move(stops_)) {}
+ Function(Stops stops_, float base_)
+ : base(base_), stops(std::move(stops_)) {
+ assert(stops.size() > 0);
+ }
float getBase() const { return base; }
const std::vector<std::pair<float, T>>& getStops() const { return stops; }