diff --git a/src/cpp/rtps/DataSharing/ReaderPool.hpp b/src/cpp/rtps/DataSharing/ReaderPool.hpp index 8c1b9db7bdd..d15b3e7bfd4 100644 --- a/src/cpp/rtps/DataSharing/ReaderPool.hpp +++ b/src/cpp/rtps/DataSharing/ReaderPool.hpp @@ -233,14 +233,18 @@ class ReaderPool : public DataSharingPayloadPool bool ensure_reading_reference_is_in_bounds() { - if ((next_payload_ >> 32) < (descriptor_->notified_end >> 32) && - static_cast(next_payload_) <= static_cast(descriptor_->notified_end)) + auto notified_end = end(); + auto notified_end_high = notified_end >> 32; + auto next_payload_high = next_payload_ >> 32; + if (next_payload_high + 1 < notified_end_high || + (next_payload_high < notified_end_high && + static_cast(next_payload_) <= static_cast(notified_end))) { logWarning(RTPS_READER, "Writer " << writer() << " overtook reader in datasharing pool." << " Some changes will be missing."); // lower part is the index, upper part is the loop counter - next_payload_ = ((next_payload_ >> 32) << 32) + static_cast(descriptor_->notified_end); + next_payload_ = ((notified_end_high - 1) << 32) + static_cast(notified_end); advance(next_payload_); return false; }