Skip to content

Commit 16f9777

Browse files
erpcgen: Fix templates for malloc errors.
If during the execution of the code the malloc fails to allocate memory appropriate checks are needed for safe execution. This patch introduces new checks to ensure safe execution. Signed-off-by: Adithya Baglody <[email protected]>
1 parent 5959ccd commit 16f9777

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

erpcgen/src/templates/c_coders.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ else
125125
{% else >%}
126126
for (uint32_t {$info.forLoopCount} = 0; {$info.forLoopCount} < {$info.sizeTemp}; ++{$info.forLoopCount})
127127
{
128+
if (!{$info.name}) break;
128129
{$addIndent(" ", info.protoNext.decode(info.protoNext))}
129130
}
130131
{% endif >%}
@@ -269,6 +270,7 @@ codec->startWriteList({% if source == "client" && info.pointerScalarTypes %}*{%
269270
{% else >%}
270271
for (uint32_t {$info.forLoopCount} = 0; {$info.forLoopCount} < {% if source == "client" && info.pointerScalarTypes %}*{% endif %}{$info.size}; ++{$info.forLoopCount})
271272
{
273+
if (!{$info.name}) break;
272274
{$addIndent(" ", info.protoNext.encode(info.protoNext))}
273275
}
274276
{% endif >%}

erpcgen/src/templates/c_common_functions.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ static void read_{$struct.name}_struct_shared(erpc::{$codecClass} * codec, {$str
144144
static void read_{$struct.name}_struct(erpc::{$codecClass} * codec, {$struct.name} * data)
145145
{% endif %}
146146
{
147+
if(NULL == data) return;
147148
{% if struct.hasNullableMember %}
148149
bool isNull;
149150
{% endif -- hasNullableMember %}
@@ -185,6 +186,7 @@ static void write_{$struct.name}_struct_shared(erpc::{$codecClass} * codec, cons
185186
static void write_{$struct.name}_struct(erpc::{$codecClass} * codec, const {$struct.name} * data)
186187
{% endif %}
187188
{
189+
if(NULL == data) return;
188190
{% for mem in struct.members if (shared == "def" && not mem.serializedViaMember) || (mem.noSharedMem && shared == "noSharedMem") %}
189191
{% if mem.isNullable %}
190192
if ({$mem.coderCall.name}{$mem.structElements} == NULL)
@@ -387,6 +389,7 @@ if ({$info.name})
387389
{% def freeArray(info) %}
388390
for (uint32_t {$info.forLoopCount} = 0; {$info.forLoopCount} < {$info.size}; ++{$info.forLoopCount})
389391
{
392+
if (!{$info.name}) break;
390393
{$addIndent(" ", info.protoNext.freeingCall(info.protoNext))}
391394
}
392395
{% enddef ------------------------------- freeArray %}

0 commit comments

Comments
 (0)