diff --git a/source/core_mqtt.c b/source/core_mqtt.c index 19863b59..1e60da09 100644 --- a/source/core_mqtt.c +++ b/source/core_mqtt.c @@ -3751,12 +3751,16 @@ void MQTT_SerializeMQTTVec( uint8_t * pAllocatedMem, { const TransportOutVector_t * pTransportVec = pVec->pVector; const size_t vecLen = pVec->vectorLen; + void * copyDest = NULL; + const void * copySource = NULL; size_t index = 0; size_t i = 0; for( i = 0; i < vecLen; i++ ) { - ( void ) memcpy( &pAllocatedMem[ index ], ( const uint8_t * ) pTransportVec[ i ].iov_base, pTransportVec[ i ].iov_len ); + copyDest = &pAllocatedMem[ index ]; + copySource = pTransportVec[ i ].iov_base; + ( void ) memcpy( copyDest, copySource, pTransportVec[ i ].iov_len ); index += pTransportVec[ i ].iov_len; } } diff --git a/source/core_mqtt_serializer.c b/source/core_mqtt_serializer.c index 262104e3..379acd1b 100644 --- a/source/core_mqtt_serializer.c +++ b/source/core_mqtt_serializer.c @@ -528,10 +528,8 @@ static uint8_t * encodeString( uint8_t * pDestination, uint16_t sourceLength ) { uint8_t * pBuffer = NULL; - - /* Typecast const char * typed source buffer to const uint8_t *. - * This is to use same type buffers in memcpy. */ - const uint8_t * pSourceBuffer = ( const uint8_t * ) pSource; + void * copyDest = NULL; + const void * copySource = NULL; assert( pDestination != NULL ); @@ -546,9 +544,11 @@ static uint8_t * encodeString( uint8_t * pDestination, pBuffer++; /* Copy the string into pBuffer. */ - if( pSourceBuffer != NULL ) + copyDest = pBuffer; + copySource = pSource; + if( copySource != NULL ) { - ( void ) memcpy( pBuffer, pSourceBuffer, sourceLength ); + ( void ) memcpy( copyDest, copySource, sourceLength ); } /* Return the pointer to the end of the encoded string. */ @@ -713,7 +713,8 @@ static void serializePublishCommon( const MQTTPublishInfo_t * pPublishInfo, bool serializePayload ) { uint8_t * pIndex = NULL; - const uint8_t * pPayloadBuffer = NULL; + void * copyDest = NULL; + const void * copySource = NULL; /* The first byte of a PUBLISH packet contains the packet type and flags. */ uint8_t publishFlags = MQTT_PACKET_TYPE_PUBLISH; @@ -787,11 +788,10 @@ static void serializePublishCommon( const MQTTPublishInfo_t * pPublishInfo, LogDebug( ( "Copying PUBLISH payload of length =%lu to buffer", ( unsigned long ) pPublishInfo->payloadLength ) ); - /* Typecast const void * typed payload buffer to const uint8_t *. - * This is to use same type buffers in memcpy. */ - pPayloadBuffer = ( const uint8_t * ) pPublishInfo->pPayload; + copyDest = pIndex; + copySource = pPublishInfo->pPayload; - ( void ) memcpy( pIndex, pPayloadBuffer, pPublishInfo->payloadLength ); + ( void ) memcpy( copyDest, copySource, pPublishInfo->payloadLength ); /* Move the index to after the payload. */ pIndex = &pIndex[ pPublishInfo->payloadLength ]; }