From cfe8e0a25a8af0d18daed86eb05d0eed76cb6916 Mon Sep 17 00:00:00 2001 From: Cervenka Dusan Date: Mon, 3 Apr 2023 15:20:53 +0200 Subject: [PATCH 1/2] Fixed memcpy for template Signed-off-by: Cervenka Dusan --- erpcgen/src/templates/c_coders.template | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/erpcgen/src/templates/c_coders.template b/erpcgen/src/templates/c_coders.template index 4d60c932..5a069c72 100644 --- a/erpcgen/src/templates/c_coders.template +++ b/erpcgen/src/templates/c_coders.template @@ -63,13 +63,16 @@ if (({$info.sizeTemp} <= {$info.maxSize}) && ({$info.dataTemp} != NULL)) {% if source == "server" || info.useMallocOnClientSide == true %} {$indent}{$info.name} = (uint8_t *) erpc_malloc({$info.maxSize} * sizeof(uint8_t)); {% if generateAllocErrorChecks == true %} -{$indent}if (({$info.name} == NULL) && ({$info.sizeTemp} > 0)) +{$indent}if ({$info.sizeTemp} > 0) {$indent}{ -{$indent} codec->updateStatus(kErpcStatus_MemoryError); -{$indent}} -{$indent}else -{$indent}{ -{$indent} memcpy({$info.name}, {$info.dataTemp}, {$info.sizeTemp}); +{$indent} if ({$info.name} == NULL) +{$indent} { +{$indent} codec->updateStatus(kErpcStatus_MemoryError); +{$indent} } +{$indent} else +{$indent} { +{$indent} memcpy({$info.name}, {$info.dataTemp}, {$info.sizeTemp}); +{$indent} } {$indent}} {% else -- generateAllocErrorChecks == true %} {$indent}memcpy({$info.name}, {$info.dataTemp}, {$info.sizeTemp}); From 3826eb8df5eb5dcad37fde939feb476692b045ea Mon Sep 17 00:00:00 2001 From: Cervenka Dusan Date: Mon, 3 Apr 2023 15:37:21 +0200 Subject: [PATCH 2/2] Cover all memcpy for length 0 Signed-off-by: Cervenka Dusan --- erpcgen/src/templates/c_coders.template | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/erpcgen/src/templates/c_coders.template b/erpcgen/src/templates/c_coders.template index 5a069c72..4bf37fa7 100644 --- a/erpcgen/src/templates/c_coders.template +++ b/erpcgen/src/templates/c_coders.template @@ -60,11 +60,11 @@ if (({$info.sizeTemp} <= {$info.maxSize}) && ({$info.dataTemp} != NULL)) {% else %} {% set indent = "" >%} {% endif %} +{$indent}if ({$info.sizeTemp} > 0) +{$indent}{ {% if source == "server" || info.useMallocOnClientSide == true %} {$indent}{$info.name} = (uint8_t *) erpc_malloc({$info.maxSize} * sizeof(uint8_t)); {% if generateAllocErrorChecks == true %} -{$indent}if ({$info.sizeTemp} > 0) -{$indent}{ {$indent} if ({$info.name} == NULL) {$indent} { {$indent} codec->updateStatus(kErpcStatus_MemoryError); @@ -73,12 +73,18 @@ if (({$info.sizeTemp} <= {$info.maxSize}) && ({$info.dataTemp} != NULL)) {$indent} { {$indent} memcpy({$info.name}, {$info.dataTemp}, {$info.sizeTemp}); {$indent} } -{$indent}} {% else -- generateAllocErrorChecks == true %} -{$indent}memcpy({$info.name}, {$info.dataTemp}, {$info.sizeTemp}); +{$indent} memcpy({$info.name}, {$info.dataTemp}, {$info.sizeTemp}); {% endif -- generateAllocErrorChecks == true %} {% else %} -{$indent}memcpy({$info.name}, {$info.dataTemp}, {$info.sizeTemp}); +{$indent} memcpy({$info.name}, {$info.dataTemp}, {$info.sizeTemp}); +{% endif %} +{$indent}} +{% if source == "server" || info.useMallocOnClientSide == true %} +{$indent}else +{$indent}{ +{$indent} {$info.name} = NULL; +{$indent}} {% endif %} {% if info.maxSize != info.sizeTemp %} }