Преглед изворни кода

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.
Jason Valenzuela пре 4 година
родитељ
комит
ff1f3d6f0b
2 измењених фајлова са 5 додато и 3 уклоњено
  1. 3 1
      source/src/cip/cipcommon.c
  2. 2 2
      source/src/cip/cipconnectionmanager.c

+ 3 - 1
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,

+ 2 - 2
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;