Skip to content
18 changes: 2 additions & 16 deletions erpc_c/infra/erpc_basic_codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,7 @@ void BasicCodec::writeData(const void *value, uint32_t length)
{
if (isStatusOk())
{
if (value != NULL)
{
m_status = m_cursor.write(value, length);
}
else
{
m_status = kErpcStatus_MemoryError;
}
m_status = m_cursor.write(value, length);
}
}

Expand Down Expand Up @@ -202,14 +195,7 @@ void BasicCodec::readData(void *value, uint32_t length)
{
if (isStatusOk())
{
if (value != NULL)
{
m_status = m_cursor.read(value, length);
}
else
{
m_status = kErpcStatus_MemoryError;
}
m_status = m_cursor.read(value, length);
}
}

Expand Down
12 changes: 10 additions & 2 deletions erpc_c/infra/erpc_message_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ erpc_status_t MessageBuffer::Cursor::read(void *data, uint32_t length)

erpc_status_t err;

if (m_remaining < length)
if ((length > 0U) && (data == NULL))
{
err = kErpcStatus_MemoryError;
}
else if (length > m_remaining)
{
err = kErpcStatus_BufferOverrun;
}
Expand All @@ -124,7 +128,11 @@ erpc_status_t MessageBuffer::Cursor::write(const void *data, uint32_t length)

erpc_status_t err;

if (length > m_remaining)
if ((length > 0U) && (data == NULL))
{
err = kErpcStatus_MemoryError;
}
else if (length > m_remaining)
{
err = kErpcStatus_BufferOverrun;
}
Expand Down
7 changes: 6 additions & 1 deletion erpcgen/src/templates/c_client_source.template
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ extern ClientManager *g_client;
{% for param in fn.parametersToClient if (param.serializedDirection == "" || param.serializedDirection == InDirection || param.referencedName != "") %}

{% if param.isNullable %}
{$clientIndent} if ({$param.nullableName} != NULL{% if ((source == "client") && (param.direction != ReturnDirection) && (empty(param.lengthName) == false)) %} && {$param.lengthName} != NULL{% endif %})
{% if ((source == "client") && (param.direction != ReturnDirection) && (empty(param.lengthName) == false)) %}
{% set lengthNameCon = ") && (" & param.lengthName & " != NULL)" >%}
{% else %}
{% set lengthNameCon = "" >%}
{% endif %}
{$clientIndent} if ({% if lengthNameCon != "" %}({% endif %}{$param.nullableName} != NULL{$lengthNameCon})
{$clientIndent} {
{$addIndent(clientIndent & " ", param.coderCall.decode(param.coderCall))}
}
Expand Down
6 changes: 3 additions & 3 deletions erpcgen/src/templates/c_coders.template
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if ({$info.sizeTemp} <= {$info.maxSize})
{% 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)
{$indent}if (({$info.name} == NULL) && ({$info.sizeTemp} > 0))
{$indent}{
{$indent} codec->updateStatus(kErpcStatus_MemoryError);
{$indent}}
Expand Down Expand Up @@ -100,7 +100,7 @@ if ({$info.sizeTemp} <= {$info.maxSize})
{% if source == "server" || info.useMallocOnClientSide == true %}
{$indent}{$info.name} = ({$info.mallocType}) erpc_malloc({$info.maxSize} * sizeof({$info.mallocSizeType}));
{% if generateAllocErrorChecks == true %}
{$indent}if ({$info.name} == NULL)
{$indent}if (({$info.name} == NULL) && ({$info.sizeTemp} > 0))
{$indent}{
{$indent} codec->updateStatus(kErpcStatus_MemoryError);
{$indent}}
Expand Down Expand Up @@ -312,7 +312,7 @@ codec->writeCallback((arrayOfFunPtr)({$info.callbacks}), {$info.callbacksCount},

{% def encodeSharedType(info) %}
{% if sharedMemBeginAddr != "" %}
if ({$info.name} >= ERPC_SHARED_MEMORY_BEGIN && {$info.name} <= ERPC_SHARED_MEMORY_END)
if (({$info.name} >= ERPC_SHARED_MEMORY_BEGIN) && ({$info.name} <= ERPC_SHARED_MEMORY_END))
{
codec->writePtr(reinterpret_cast<uintptr_t>({%if source == "client" && info.InoutOutDirection %}*{% endif %}{$info.name}));
}
Expand Down
7 changes: 6 additions & 1 deletion erpcgen/src/templates/c_common_functions.template
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,12 @@ struct
{% enddef ------------------------------- unionMembersDeclaration %}

{% def f_paramIsNullableEncode(param) %}
if ({$param.nullableName} == NULL{% if ((source == "client") && (param.direction != ReturnDirection) && (empty(param.lengthName) == false)) %} || {$param.lengthName} == NULL{% endif %})
{% if ((source == "client") && (param.direction != ReturnDirection) && (empty(param.lengthName) == false)) %}
{% set lengthNameCon = ") || (" & param.lengthName & " == NULL)" >%}
{% else %}
{% set lengthNameCon = "" >%}
{% endif %}
if ({% if lengthNameCon != "" %}({% endif %}{$param.nullableName} == NULL{$lengthNameCon})
{
codec->writeNullFlag(true);
}
Expand Down
2 changes: 1 addition & 1 deletion erpcgen/src/templates/c_server_source.template
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ ERPC_MANUALLY_CONSTRUCTED_STATIC({$iface.serviceClassName}, s_{$iface.serviceCla
#endif
{% if serverIDName == "serviceID" %}
{% for callbackFunction in callbackType.functions %}
{$serverIndent} {% if loop.first == false %}else {% endif %}if ({$serverIDName} == {$callbackFunction.serviceId} && {$functionIDName} == {$callbackFunction.id})
{$serverIndent} {% if loop.first == false %}else {% endif %}if (({$serverIDName} == {$callbackFunction.serviceId}) && ({$functionIDName} == {$callbackFunction.id}))
{$serverIndent} {
{$serverIndent} {$callbackFunction.serverPrototype}
{$serverIndent} }
Expand Down
6 changes: 3 additions & 3 deletions erpcgen/test/test_nullable_c.yml
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ test_client.cpp:
- void bar(const bool * l, uint32_t c)
- if: dir == 'inout' and ann == '@nullable'
then:
- if (l == NULL || c == NULL)
- if ((l == NULL) || (c == NULL))
else:
- if (l == NULL)
- codec->writeNullFlag
Expand Down Expand Up @@ -398,7 +398,7 @@ test_client.cpp:
- void bar(bool * l, uint32_t * c)
- if: ann == '@nullable'
then:
- if (l == NULL || c == NULL)
- if ((l == NULL) || (c == NULL))
else:
- if (l == NULL)
- codec->writeNullFlag
Expand All @@ -412,7 +412,7 @@ test_client.cpp:
- codec->write
- if: ann == '@nullable'
then:
- if (l != NULL && c != NULL)
- if ((l != NULL) && (c != NULL))
else:
- if (l != NULL)
- codec->startReadList
Expand Down
14 changes: 14 additions & 0 deletions test/test_lists/test_lists_client_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ TEST(test_list, SendReceivedInt32)
erpc_free(received_list);
}

TEST(test_list, sendReceiveZeroSize)
{
list_int32_1_t *received_list, send_list;
send_list.elementsCount = 0;
send_list.elements = NULL;

received_list = sendReceivedInt32(&send_list);

EXPECT_TRUE(received_list->elementsCount == 0);

erpc_free(received_list->elements);
erpc_free(received_list);
}

TEST(test_list, SendReceived2Int32)
{
list_int32_2_t *received_list, send_list;
Expand Down