Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit f778624

Browse files
committed
fix warnings on Windows
1 parent 8eaeb9e commit f778624

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

rmw_connext_cpp/src/rmw_publish.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include <limits>
16+
1517
#include "rmw/error_handling.h"
1618
#include "rmw/rmw.h"
1719
#include "rmw/types.h"
@@ -43,9 +45,13 @@ publish(DDSDataWriter * dds_data_writer, ConnextStaticCDRStream * cdr_stream)
4345
DDS_ReturnCode_t status = DDS_RETCODE_ERROR;
4446

4547
instance->serialized_data.maximum(0);
48+
if (cdr_stream->buffer_length > (std::numeric_limits<DDS_Long>::max)()) {
49+
RMW_SET_ERROR_MSG("cdr_stream->buffer_length unexpectedly larger than DDS_Long's max value");
50+
return false;
51+
}
4652
if (!instance->serialized_data.loan_contiguous(
4753
reinterpret_cast<DDS_Octet *>(cdr_stream->buffer),
48-
cdr_stream->buffer_length, cdr_stream->buffer_length))
54+
static_cast<DDS_Long>(cdr_stream->buffer_length), cdr_stream->buffer_length))
4955
{
5056
RMW_SET_ERROR_MSG("failed to loan memory for message");
5157
goto cleanup;

rmw_connext_cpp/src/rmw_take.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include <limits>
16+
1517
#include "rmw/error_handling.h"
1618
#include "rmw/impl/cpp/macros.hpp"
1719
#include "rmw/types.h"
@@ -105,7 +107,14 @@ take(
105107
// TODO(karsten1987): This malloc has to go!
106108
cdr_stream->buffer =
107109
reinterpret_cast<char *>(malloc(cdr_stream->buffer_length * sizeof(char)));
108-
for (size_t i = 0; i < cdr_stream->buffer_length; ++i) {
110+
111+
if (cdr_stream->buffer_length > (std::numeric_limits<unsigned int>::max)()) {
112+
RMW_SET_ERROR_MSG("cdr_stream->buffer_length unexpectedly larger than max unsiged int value");
113+
data_reader->return_loan(dds_messages, sample_infos);
114+
*taken = false;
115+
return DDS_RETCODE_ERROR;
116+
}
117+
for (unsigned int i = 0; i < static_cast<unsigned int>(cdr_stream->buffer_length); ++i) {
109118
cdr_stream->buffer[i] = dds_messages[0].serialized_data[i];
110119
}
111120
*taken = true;

0 commit comments

Comments
 (0)