Skip to content
This repository was archived by the owner on May 6, 2024. It is now read-only.

Commit 7912f2d

Browse files
EinarElentomeichlersmith
authored andcommitted
Missed range check
1 parent 768160f commit 7912f2d

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/SimCore/TrackMap.cxx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66

77
namespace simcore {
88

9-
void TrackMap::isDescendant(int trackID, int ancestorID,
9+
bool TrackMap::isDescendant(int trackID, int ancestorID,
1010
int maximum_depth) const {
1111
int current_depth{0};
1212
int current_track{trackID};
13-
while (current_depth < maximum_depth) {
13+
// Walk the tree until we either no longer have a parent or we reach the
14+
// desired depth
15+
while (current_depth < maximum_depth &&
16+
(ancestry_.find(current_track) != ancestry_.end())) {
17+
// See if we have encountered the parent of the current track
18+
//
19+
// operator[] is not const, so we need to use at()
1420
current_track = ancestry_.at(current_track).first;
1521
if (current_track == ancestorID) {
22+
// If one of the parents is the track of interest, we are done!
1623
return true;
1724
}
1825
current_depth++;

0 commit comments

Comments
 (0)