donghao526 commented on code in PR #3130:
URL: https://github.com/apache/kvrocks/pull/3130#discussion_r2467821962
##########
src/types/redis_tdigest.cc:
##########
@@ -67,18 +67,18 @@ class DummyCentroids {
if (Valid()) {
std::advance(iter_, 1);
}
- return iter_ != centroids_.cend();
+ return Valid();
}
// The Prev function can only be called for item is not cend,
// because we must guarantee the iterator to be inside the valid range
before iteration.
bool Prev() {
- if (Valid() && iter_ != centroids_.cbegin()) {
+ if (Valid()) {
std::advance(iter_, -1);
}
return Valid();
}
- bool Valid() const { return iter_ != centroids_.cend(); }
+ bool Valid() const { return iter_ < centroids_.cend() && iter_ >=
centroids_.cbegin(); }
Review Comment:
I found when traversing the centroids_ in reverse , if the iter_ ==
cbegin(), traversal cannot be stopped by using Valid(). But there is indeed a
risk of iterator out of bounds here.
Instead, I decided to use IsBegin() to explicit break the loop.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]