ソースを参照

Change msg router request data size to size_t.

Resolves signed/unsigned warnings arising from comparisons of the
request_data_size member with unsigned quantities, e.g., Visual Studio
C4018.

DecodePaddedEPath() was modified to change the consumed bytes value
into a size_t output parameter while still supporting error return
values, which may be negative. The new size_t type is better suited for
this type of value and this function's use cases.
Jason Valenzuela 1 年間 前
コミット
1e99582227

+ 6 - 3
source/src/cip/cipcommon.c

@@ -1385,8 +1385,10 @@ void EncodeEPath(const void *const data,
     message->used_message_length - start_length);
 }
 
-int DecodePaddedEPath(CipEpath *epath,
-                      const EipUint8 **message) {
+EipStatus DecodePaddedEPath(CipEpath *epath,
+                            const EipUint8 **message,
+                            size_t *const bytes_consumed) {
+  OPENER_ASSERT(bytes_consumed != NULL);
   unsigned int number_of_decoded_elements = 0;
   const EipUint8 *message_runner = *message;
 
@@ -1461,7 +1463,8 @@ int DecodePaddedEPath(CipEpath *epath,
   }
 
   *message = message_runner;
-  return number_of_decoded_elements * 2 + 1; /* number_of_decoded_elements times 2 as every encoding uses 2 bytes */
+  *bytes_consumed = number_of_decoded_elements * sizeof(CipWord) + 1; /* number_of_decoded_elements times 2 as every encoding uses 2 bytes */
+  return kEipStatusOk;
 }
 
 EipStatus CipCreateService(CipInstance *RESTRICT const instance,

+ 8 - 3
source/src/cip/cipcommon.h

@@ -147,10 +147,15 @@ EipStatus SetAttributeList(CipInstance *instance,
 /** @brief Decodes padded EPath
  *  @param epath EPath object to the receiving element
  *  @param message pointer to the message to decode
- *  @return Number of decoded bytes
+ *  @param[out] bytes_decoded Location to store the number of bytes consumed
+ *                            from the message buffer.
+ *  @return @link EipStatus kEipStatusOk @endlink if successful, or
+ *          @link EipStatus kEipStatusError @endlink if the path
+ *          could not be parsed.
  */
-int DecodePaddedEPath(CipEpath *epath,
-                      const EipUint8 **message);
+EipStatus DecodePaddedEPath(CipEpath *epath,
+                            const EipUint8 **message,
+                            size_t *const bytes_decoded);
 
 /** @brief Generic implementation of the CIP Create service
  *

+ 10 - 8
source/src/cip/cipmessagerouter.c

@@ -249,19 +249,21 @@ CipError CreateMessageRouterRequestStructure(const EipUint8 *data,
   data++;
   data_length--;
 
-  int number_of_decoded_bytes =
-    DecodePaddedEPath(&(message_router_request->request_path), &data);
-  if(number_of_decoded_bytes < 0) {
+  size_t number_of_decoded_bytes;
+  const EipStatus path_result =
+    DecodePaddedEPath(&(message_router_request->request_path),
+                      &data,
+                      &number_of_decoded_bytes);
+  if(path_result != kEipStatusOk) {
     return kCipErrorPathSegmentError;
   }
 
-  message_router_request->data = data;
-  message_router_request->request_data_size = data_length -
-                                              number_of_decoded_bytes;
-
-  if(message_router_request->request_data_size < 0) {
+  if(number_of_decoded_bytes > data_length) {
     return kCipErrorPathSizeInvalid;
   } else {
+    message_router_request->data = data;
+    message_router_request->request_data_size = data_length -
+                                                number_of_decoded_bytes;
     return kCipErrorSuccess;
   }
 }

+ 1 - 1
source/src/cip/ciptypes.h

@@ -265,7 +265,7 @@ typedef struct {
 typedef struct {
   CipUsint service;
   CipEpath request_path;
-  EipInt16 request_data_size;
+  size_t request_data_size;
   const CipOctet *data;
 } CipMessageRouterRequest;