Skip to content

Commit 549428a

Browse files
Fix corner case RTPSParticipantImpl max_data_size < overhead
Signed-off-by: Eugenio Collado <[email protected]>
1 parent a9ad12f commit 549428a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/cpp/rtps/participant/RTPSParticipantImpl.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,20 +2312,22 @@ uint32_t RTPSParticipantImpl::getMaxDataSize()
23122312
uint32_t RTPSParticipantImpl::calculateMaxDataSize(
23132313
uint32_t length)
23142314
{
2315-
uint32_t maxDataSize = length;
2316-
2315+
// RTPS header
2316+
uint32_t overhead = RTPSMESSAGE_HEADER_SIZE;
23172317
#if HAVE_SECURITY
23182318
// If there is rtps messsage protection, reduce max size for messages,
23192319
// because extra data is added on encryption.
23202320
if (security_attributes_.is_rtps_protected)
23212321
{
2322-
maxDataSize -= m_security_manager.calculate_extra_size_for_rtps_message();
2322+
overhead += m_security_manager.calculate_extra_size_for_rtps_message();
23232323
}
23242324
#endif // if HAVE_SECURITY
23252325

2326-
// RTPS header
2327-
maxDataSize -= RTPSMESSAGE_HEADER_SIZE;
2328-
return maxDataSize;
2326+
if (length <= overhead)
2327+
{
2328+
return 0;
2329+
}
2330+
return length - overhead;
23292331
}
23302332

23312333
bool RTPSParticipantImpl::networkFactoryHasRegisteredTransports() const

0 commit comments

Comments
 (0)