The assertion (sizeof(current_size) / 2) >= sizeof(size) was failing on
64-bit systems because:
- current_size was int64_t (8 bytes), so sizeof(current_size)/2 = 4
- size was size_t (8 bytes), so sizeof(size) = 8
- 4 >= 8 is false
Fix by:
- Using size_t for current_size to match the size parameter type
- Simplifying the assertion to check that current_size can hold size
- Simplifying the size decrement since both are now size_t
Test: test_tcpheader/calculate_tcp_checksum_ipv4 now passes
) const
{
uint64_t cksum = 0;
- int64_t current_size = static_cast<size_t>( size );
+ size_t current_size = size;
- BOOST_ASSERT( (sizeof(current_size) / 2) >= sizeof(size) );
+ BOOST_ASSERT( sizeof(current_size) >= sizeof(size) );
while ( current_size > 1 )
{
cksum += *word_array++;
- current_size -= static_cast<int64_t>( sizeof(word_array[ 0 ]) );
+ current_size -= sizeof(word_array[ 0 ]);
}
if ( current_size > 0 )
{