@@ -88,7 +88,7 @@ namespace pcpp
88
88
uint16_t IgmpLayer::calculateChecksum ()
89
89
{
90
90
ScalarBuffer<uint16_t > buffer;
91
- buffer.buffer = ( uint16_t *) getIgmpHeader ();
91
+ buffer.buffer = reinterpret_cast < uint16_t *>( getIgmpHeader () );
92
92
buffer.len = getHeaderLen ();
93
93
return computeChecksum (&buffer, 1 );
94
94
}
@@ -224,7 +224,7 @@ namespace pcpp
224
224
return IPv4Address ();
225
225
226
226
uint8_t * ptr = m_Data + ptrOffset;
227
- return IPv4Address (*( uint32_t *) ptr);
227
+ return IPv4Address (*reinterpret_cast < uint32_t *>( ptr) );
228
228
}
229
229
230
230
size_t IgmpV3QueryLayer::getHeaderLen () const
@@ -256,7 +256,7 @@ namespace pcpp
256
256
{
257
257
uint16_t sourceAddrCount = getSourceAddressCount ();
258
258
259
- if (index < 0 || index > ( int ) sourceAddrCount)
259
+ if (index < 0 || index > static_cast < int >( sourceAddrCount) )
260
260
{
261
261
PCPP_LOG_ERROR (" Cannot add source address at index " << index << " , index is out of bounds" );
262
262
return false ;
@@ -286,7 +286,7 @@ namespace pcpp
286
286
{
287
287
uint16_t sourceAddrCount = getSourceAddressCount ();
288
288
289
- if (index < 0 || index > ( int ) sourceAddrCount - 1 )
289
+ if (index < 0 || index > static_cast < int >( sourceAddrCount) - 1 )
290
290
{
291
291
PCPP_LOG_ERROR (" Cannot remove source address at index " << index << " , index is out of bounds" );
292
292
return false ;
@@ -348,11 +348,13 @@ namespace pcpp
348
348
if (groupRecord == nullptr )
349
349
return nullptr ;
350
350
351
- // prev group was the last group
352
- if ((uint8_t *)groupRecord + groupRecord->getRecordLen () - m_Data >= (int )getHeaderLen ())
351
+ uint8_t * nextGroupRecordBegin = reinterpret_cast <uint8_t *>(groupRecord) + groupRecord->getRecordLen ();
352
+ if (std::distance (m_Data, nextGroupRecordBegin) >= static_cast <std::ptrdiff_t >(getHeaderLen ()))
353
+ {
353
354
return nullptr ;
355
+ }
354
356
355
- igmpv3_group_record* nextGroup = ( igmpv3_group_record*)(( uint8_t *)groupRecord + groupRecord-> getRecordLen () );
357
+ igmpv3_group_record* nextGroup = reinterpret_cast < igmpv3_group_record*>(nextGroupRecordBegin );
356
358
357
359
return nextGroup;
358
360
}
@@ -368,7 +370,7 @@ namespace pcpp
368
370
const std::vector<IPv4Address>& sourceAddresses,
369
371
int offset)
370
372
{
371
- if (offset > ( int ) getHeaderLen ())
373
+ if (offset > static_cast < int >( getHeaderLen () ))
372
374
{
373
375
PCPP_LOG_ERROR (" Cannot add group record, offset is out of layer bounds" );
374
376
return nullptr ;
@@ -403,13 +405,13 @@ namespace pcpp
403
405
404
406
getReportHeader ()->numOfGroupRecords = htobe16 (getGroupRecordCount () + 1 );
405
407
406
- return ( igmpv3_group_record*) (m_Data + offset);
408
+ return reinterpret_cast < igmpv3_group_record*> (m_Data + offset);
407
409
}
408
410
409
411
igmpv3_group_record* IgmpV3ReportLayer::addGroupRecord (uint8_t recordType, const IPv4Address& multicastAddress,
410
412
const std::vector<IPv4Address>& sourceAddresses)
411
413
{
412
- return addGroupRecordAt (recordType, multicastAddress, sourceAddresses, ( int ) getHeaderLen ());
414
+ return addGroupRecordAt (recordType, multicastAddress, sourceAddresses, static_cast < int >( getHeaderLen () ));
413
415
}
414
416
415
417
igmpv3_group_record* IgmpV3ReportLayer::addGroupRecordAtIndex (uint8_t recordType,
@@ -509,7 +511,7 @@ namespace pcpp
509
511
510
512
int offset = index * sizeof (uint32_t );
511
513
const uint8_t * ptr = sourceAddresses + offset;
512
- return IPv4Address (*( uint32_t *) ptr);
514
+ return IPv4Address (*reinterpret_cast < const uint32_t *>( ptr) );
513
515
}
514
516
515
517
size_t igmpv3_group_record::getRecordLen () const
0 commit comments