Skip to content

Commit

Permalink
Cast size_t to uint32_t explicitly. (ros2#171)
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <[email protected]>
  • Loading branch information
hidmic authored Apr 28, 2020
1 parent 03a49c5 commit 3c306d3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion rmw_cyclonedds_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <tuple>
#include <utility>
#include <regex>
#include <limits>

#include "rcutils/filesystem.h"
#include "rcutils/format_string.h"
Expand Down Expand Up @@ -2186,11 +2187,19 @@ static rmw_ret_t rmw_take_seq(
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);
RET_NULL(sub);

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.
if (ret < 0) {
Expand Down

0 comments on commit 3c306d3

Please sign in to comment.