Cast size_t to uint32_t explicitly. (#171)

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
This commit is contained in:
Michel Hidalgo 2020-04-28 14:37:00 -03:00 committed by GitHub
parent 03a49c5153
commit 3c306d32a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,6 +26,7 @@
#include <tuple> #include <tuple>
#include <utility> #include <utility>
#include <regex> #include <regex>
#include <limits>
#include "rcutils/filesystem.h" #include "rcutils/filesystem.h"
#include "rcutils/format_string.h" #include "rcutils/format_string.h"
@ -2186,11 +2187,19 @@ static rmw_ret_t rmw_take_seq(
return RMW_RET_ERROR; return RMW_RET_ERROR;
} }
if (count > (std::numeric_limits<uint32_t>::max)()) {
RMW_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Cannot take %ld samples at once, limit is %d",
count, (std::numeric_limits<uint32_t>::max)());
return RMW_RET_ERROR;
}
CddsSubscription * sub = static_cast<CddsSubscription *>(subscription->data); CddsSubscription * sub = static_cast<CddsSubscription *>(subscription->data);
RET_NULL(sub); RET_NULL(sub);
std::vector<dds_sample_info_t> infos(count); std::vector<dds_sample_info_t> infos(count);
auto ret = dds_take(sub->enth, message_sequence->data, infos.data(), count, count); auto maxsamples = static_cast<uint32_t>(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. // Returning 0 should not be an error, as it just indicates that no messages were available.
if (ret < 0) { if (ret < 0) {