From ee59c3d0747286a6de9dc93104ac20be2f641045 Mon Sep 17 00:00:00 2001 From: Jason Valenzuela Date: Tue, 4 Jan 2022 22:33:29 -0500 Subject: [PATCH] Fix data parameter for attribute decoding functions. This involves two changes: 1. Remove const data qualifier from the CipAttributeDecodeFromMessage function pointer type. Decoding functions are intended to modify the attribute data, therefore the attribute data cannot be constant. 2. Make the data parameter for all decoding functions void * to match the CipAttributeDecodeFromMessage type. Resolves compiler warnings about parameters differing from declaration, e.g. C4028 and -Wincompatible-pointer-types. --- source/src/cip/cipassembly.c | 10 +++++----- source/src/cip/cipqos.c | 4 ++-- source/src/cip/ciptcpipinterface.c | 8 ++++---- source/src/cip/ciptypes.h | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/src/cip/cipassembly.c b/source/src/cip/cipassembly.c index 413513eb4..2709761ec 100644 --- a/source/src/cip/cipassembly.c +++ b/source/src/cip/cipassembly.c @@ -26,7 +26,7 @@ * @return length of taken bytes * -1 .. error */ -int DecodeCipAssemblyAttribute3(CipByteArray *const data, +int DecodeCipAssemblyAttribute3(void *const data, CipMessageRouterRequest *const message_router_request, CipMessageRouterResponse *const message_router_response); @@ -152,7 +152,7 @@ EipStatus NotifyAssemblyConnectedDataReceived(CipInstance *const instance, return AfterAssemblyDataReceived(instance); } -int DecodeCipAssemblyAttribute3(CipByteArray *const data, +int DecodeCipAssemblyAttribute3(void *const data, CipMessageRouterRequest *const message_router_request, CipMessageRouterResponse *const message_router_response) { @@ -163,15 +163,15 @@ int DecodeCipAssemblyAttribute3(CipByteArray *const data, int number_of_decoded_bytes = -1; OPENER_TRACE_INFO(" -> set Assembly attribute byte array\r\n"); - CipByteArray *cip_byte_array = data; + CipByteArray *cip_byte_array = (CipByteArray *)data; - if(message_router_request->request_data_size < data->length) { + if(message_router_request->request_data_size < cip_byte_array->length) { OPENER_TRACE_INFO( "DecodeCipByteArray: not enough data received.\n"); message_router_response->general_status = kCipErrorNotEnoughData; return number_of_decoded_bytes; } - if(message_router_request->request_data_size > data->length) { + if(message_router_request->request_data_size > cip_byte_array->length) { OPENER_TRACE_INFO( "DecodeCipByteArray: too much data received.\n"); message_router_response->general_status = kCipErrorTooMuchData; diff --git a/source/src/cip/cipqos.c b/source/src/cip/cipqos.c index a0f0e86e8..8598f9eac 100644 --- a/source/src/cip/cipqos.c +++ b/source/src/cip/cipqos.c @@ -68,7 +68,7 @@ static CipQosDscpValues s_active_dscp = { * @return length of taken bytes * -1 .. error */ -int DecodeCipQoSAttribute(CipUsint *const data, +int DecodeCipQoSAttribute(void *const data, CipMessageRouterRequest *const message_router_request, CipMessageRouterResponse *const message_router_response) { @@ -81,7 +81,7 @@ int DecodeCipQoSAttribute(CipUsint *const data, CipUsint attribute_value_received = GetUsintFromMessage(&cip_message); if (attribute_value_received < 64U) { - *data = attribute_value_received; //write value to attribute + *(CipUsint *)data = attribute_value_received; //write value to attribute message_router_response->general_status = kCipErrorSuccess; number_of_decoded_bytes = 1; diff --git a/source/src/cip/ciptcpipinterface.c b/source/src/cip/ciptcpipinterface.c index 616543e40..e95e0a512 100644 --- a/source/src/cip/ciptcpipinterface.c +++ b/source/src/cip/ciptcpipinterface.c @@ -373,7 +373,7 @@ void EncodeCipLastConflictDetected(const void *const data, int DecodeTcpIpInterfaceConfigurationControl( /* Attribute 3 */ - CipDword *const data, + void *const data, CipMessageRouterRequest *const message_router_request, CipMessageRouterResponse *const message_router_response) { @@ -392,7 +392,7 @@ int DecodeTcpIpInterfaceConfigurationControl( /* Attribute 3 */ configuration_control_received &= (kTcpipCfgCtrlMethodMask | kTcpipCfgCtrlDnsEnable); - *data = configuration_control_received; + *(CipDword *)data = configuration_control_received; number_of_decoded_bytes = 4; message_router_response->general_status = kCipErrorSuccess; } @@ -510,7 +510,7 @@ int DecodeCipTcpIpInterfaceHostName( /* Attribute 6 */ #endif /* defined (OPENER_TCPIP_IFACE_CFG_SETTABLE) && 0 != OPENER_TCPIP_IFACE_CFG_SETTABLE*/ int DecodeCipTcpIpInterfaceEncapsulationInactivityTimeout( /* Attribute 13 */ - CipUint *const data, + void *const data, CipMessageRouterRequest *const message_router_request, CipMessageRouterResponse *const message_router_response) { @@ -524,7 +524,7 @@ int DecodeCipTcpIpInterfaceEncapsulationInactivityTimeout( /* Attribute 13 */ kCipErrorInvalidAttributeValue; } else { - *data = inactivity_timeout_received; + *(CipUint *)data = inactivity_timeout_received; message_router_response->general_status = kCipErrorSuccess; number_of_decoded_bytes = 2; diff --git a/source/src/cip/ciptypes.h b/source/src/cip/ciptypes.h index aa7558173..7529669b7 100644 --- a/source/src/cip/ciptypes.h +++ b/source/src/cip/ciptypes.h @@ -295,7 +295,7 @@ typedef void (*CipAttributeEncodeInMessage)(const void *const data, ENIPMessage *const outgoing_message); /** @brief self-describing data decoding for CIP types */ -typedef int (*CipAttributeDecodeFromMessage)(const void *const data, +typedef int (*CipAttributeDecodeFromMessage)(void *const data, CipMessageRouterRequest * const message_router_request, CipMessageRouterResponse *const