Skip to content

Commit 8905282

Browse files
committed
Fix out-of-range bug in contour's axes_objects (#71)
1 parent fac11a2 commit 8905282

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

source/matplot/axes_objects/contours.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,9 +1019,12 @@ namespace matplot {
10191019
} else {
10201020
// Skip the next nans separating parents and children
10211021
// to avoid extra useless empty lines in case there is
1022-
// more than one nan
1023-
while (is_separator(lines_[i].first[j + 1],
1024-
lines_[i].second[j + 1])) {
1022+
// more than one nan (with out-of-bounds check if we
1023+
// have a corner case then the lines_ has one or more
1024+
// nans at end of the underlying storage)
1025+
while (j + 1 < lines_[i].first.size() &&
1026+
is_separator(lines_[i].first[j + 1],
1027+
lines_[i].second[j + 1])) {
10251028
++j;
10261029
}
10271030
// Include an empty line to indicate this polygon or line
@@ -1712,4 +1715,4 @@ namespace matplot {
17121715
return *this;
17131716
}
17141717

1715-
} // namespace matplot
1718+
} // namespace matplot

0 commit comments

Comments
 (0)