From 15f5f17988aac2c5781b96ec532a2a3201aba4e3 Mon Sep 17 00:00:00 2001 From: Jason Valenzuela Date: Fri, 18 Mar 2022 20:49:40 -0400 Subject: [PATCH] Replace path word size constants with sizeof(). Resolves some signed/unsigned comparison warnings, e.g., Visual Studio C4018 and C4389, and removes some magic numbers. --- source/src/cip/cipcommon.c | 4 +++- source/src/cip/cipconnectionmanager.c | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/source/src/cip/cipcommon.c b/source/src/cip/cipcommon.c index 62f9b4d18..8e680e980 100644 --- a/source/src/cip/cipcommon.c +++ b/source/src/cip/cipcommon.c @@ -1378,8 +1378,10 @@ void EncodeEPath(const CipEpath *const epath, } } + /* path size is in 16 bit chunks according to the specification */ OPENER_ASSERT( - epath->path_size * 2 == message->used_message_length - start_length); /* path size is in 16 bit chunks according to the specification */ + epath->path_size * sizeof(CipWord) == + message->used_message_length - start_length); } int DecodePaddedEPath(CipEpath *epath, diff --git a/source/src/cip/cipconnectionmanager.c b/source/src/cip/cipconnectionmanager.c index e5609bcc1..44cbe0b38 100644 --- a/source/src/cip/cipconnectionmanager.c +++ b/source/src/cip/cipconnectionmanager.c @@ -1352,14 +1352,14 @@ EipUint8 ParseConnectionPath(CipConnectionObject *connection_object, header_length = g_kLargeForwardOpenHeaderLength; } - if( (header_length + remaining_path * 2) < + if( ( header_length + remaining_path * sizeof(CipWord) ) < message_router_request->request_data_size ) { /* the received packet is larger than the data in the path */ *extended_error = 0; return kCipErrorTooMuchData; } - if( (header_length + remaining_path * 2) > + if( ( header_length + remaining_path * sizeof(CipWord) ) > message_router_request->request_data_size ) { /*there is not enough data in received packet */ *extended_error = 0;