From 3c306d32a699642c14b7c23255a41d56a65dbf58 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Tue, 28 Apr 2020 14:37:00 -0300 Subject: [PATCH] Cast size_t to uint32_t explicitly. (#171) Signed-off-by: Michel Hidalgo --- rmw_cyclonedds_cpp/src/rmw_node.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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) {