From 2fb53a08f5529e3eea09fba29abd7a8ab3af9a1b Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Sat, 27 Dec 2025 18:28:09 +0100 Subject: [PATCH] tcpheader: Fix BOOST_ASSERT failure in calculate_checksum 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 --- src/tcp/tcpheader.cpp | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tcp/tcpheader.cpp b/src/tcp/tcpheader.cpp index 5eedee5..bef7888 100644 --- a/src/tcp/tcpheader.cpp +++ b/src/tcp/tcpheader.cpp @@ -551,14 +551,14 @@ uint16_t TcpHeader::calculate_checksum( ) const { uint64_t cksum = 0; - int64_t current_size = static_cast( 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( sizeof(word_array[ 0 ]) ); + current_size -= sizeof(word_array[ 0 ]); } if ( current_size > 0 ) { -- 1.7.1