Skip to content

Commit 9cd81bf

Browse files
author
leha-bot
committed
Fix out-of-range bug in contour::process_all_segs_and_all_kinds() (#73)
1 parent 903d1aa commit 9cd81bf

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

source/matplot/axes_objects/contours.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,11 @@ namespace matplot {
16301630
std::get<2>(cur_child) = j;
16311631
std::get<1>(cur).emplace_back(cur_child);
16321632
}
1633+
// check for bounds before accessing value and
1634+
// break while loop if fails.
1635+
if (j + 1 >= filled_lines_[i].first.size()) {
1636+
break;
1637+
}
16331638
// Two nans in a row indicate a new parent
16341639
bool only_one_nan =
16351640
std::isfinite(filled_lines_[i].first[j + 1]);
@@ -1645,7 +1650,8 @@ namespace matplot {
16451650
line_segments_.emplace_back(cur);
16461651
std::get<1>(cur).clear();
16471652
++j;
1648-
while (!std::isfinite(filled_lines_[i].first[j])) {
1653+
while (j < filled_lines_[i].first.size() &&
1654+
!std::isfinite(filled_lines_[i].first[j])) {
16491655
++j;
16501656
}
16511657
// start new parent

0 commit comments

Comments
 (0)