diff --git a/rmw_cyclonedds_cpp/src/rmw_node.cpp b/rmw_cyclonedds_cpp/src/rmw_node.cpp index 497800e7..e4f5e5ad 100644 --- a/rmw_cyclonedds_cpp/src/rmw_node.cpp +++ b/rmw_cyclonedds_cpp/src/rmw_node.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "rcutils/filesystem.h" #include "rcutils/format_string.h" @@ -2186,11 +2187,19 @@ static rmw_ret_t rmw_take_seq( return RMW_RET_ERROR; } + if (count > (std::numeric_limits::max)()) { + RMW_SET_ERROR_MSG_WITH_FORMAT_STRING( + "Cannot take %ld samples at once, limit is %d", + count, (std::numeric_limits::max)()); + return RMW_RET_ERROR; + } + CddsSubscription * sub = static_cast(subscription->data); RET_NULL(sub); std::vector infos(count); - auto ret = dds_take(sub->enth, message_sequence->data, infos.data(), count, count); + auto maxsamples = static_cast(count); + auto ret = dds_take(sub->enth, message_sequence->data, infos.data(), count, maxsamples); // Returning 0 should not be an error, as it just indicates that no messages were available. if (ret < 0) {