Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix misra erpc c #158

Merged
merged 14 commits into from
Feb 17, 2021
51 changes: 22 additions & 29 deletions erpc_c/infra/erpc_arbitrated_client_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
* Copyright 2021 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
Expand Down Expand Up @@ -39,10 +40,11 @@ void ArbitratedClientManager::setArbitrator(TransportArbitrator *arbitrator)

void ArbitratedClientManager::performClientRequest(RequestContext &request)
{
assert(m_arbitrator && "arbitrator not set");

erpc_status_t err;
TransportArbitrator::client_token_t token = 0;

assert(m_arbitrator && "arbitrator not set");

// Set up the client receive before we send the request, so if the reply is sent
// before we get to the clientReceive() call below the arbitrator already has the buffer.
if (!request.isOneway())
Expand All @@ -51,63 +53,54 @@ void ArbitratedClientManager::performClientRequest(RequestContext &request)
if (nestingDetection)
{
request.getCodec()->updateStatus(kErpcStatus_NestedCallFailure);
return;
}
#endif
token = m_arbitrator->prepareClientReceive(request);
if (!token)
if (request.getCodec()->isStatusOk() == true)
{
request.getCodec()->updateStatus(kErpcStatus_Fail);
return;
token = m_arbitrator->prepareClientReceive(request);
if (!token)
{
request.getCodec()->updateStatus(kErpcStatus_Fail);
}
}
}

erpc_status_t err;

#if ERPC_MESSAGE_LOGGING
err = logMessage(request.getCodec()->getBuffer());
if (err)
if (request.getCodec()->isStatusOk() == true)
{
err = logMessage(request.getCodec()->getBuffer());
request.getCodec()->updateStatus(err);
return;
}
#endif

// Send the request.
err = m_arbitrator->send(request.getCodec()->getBuffer());
if (err)
if (request.getCodec()->isStatusOk() == true)
{
err = m_arbitrator->send(request.getCodec()->getBuffer());
request.getCodec()->updateStatus(err);
return;
}

if (!request.isOneway())
{
// Complete the receive through the arbitrator.
err = m_arbitrator->clientReceive(token);
if (err)
if (request.getCodec()->isStatusOk() == true)
{
// Complete the receive through the arbitrator.
err = m_arbitrator->clientReceive(token);
request.getCodec()->updateStatus(err);
return;
}

#if ERPC_MESSAGE_LOGGING
err = logMessage(request.getCodec()->getBuffer());
if (err)
if (request.getCodec()->isStatusOk() == true)
{
err = logMessage(request.getCodec()->getBuffer());
request.getCodec()->updateStatus(err);
return;
}
#endif

// Check the reply.
err = verifyReply(request);
if (err)
if (request.getCodec()->isStatusOk() == true)
{
request.getCodec()->updateStatus(err);
return;
// Check the reply.
verifyReply(request);
}
}

return;
}
41 changes: 27 additions & 14 deletions erpc_c/infra/erpc_basic_codec.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2014, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* Copyright 2021 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
Expand All @@ -17,7 +18,7 @@ using namespace erpc;
// Code
////////////////////////////////////////////////////////////////////////////////

const uint32_t BasicCodec::kBasicCodecVersion = 1;
const uint8_t BasicCodec::kBasicCodecVersion = 1;

void BasicCodec::startWriteMessage(message_type_t type, uint32_t service, uint32_t request, uint32_t sequence)
{
Expand Down Expand Up @@ -47,6 +48,7 @@ void BasicCodec::write(bool value)
{
// Make sure the bool is a single byte.
uint8_t v = value;

writeData(&v, sizeof(v));
}

Expand Down Expand Up @@ -103,6 +105,7 @@ void BasicCodec::write(double value)
void BasicCodec::writePtr(uintptr_t value)
{
uint8_t ptrSize = sizeof(value);

write(ptrSize);

writeData(&value, ptrSize);
Expand Down Expand Up @@ -141,16 +144,19 @@ void BasicCodec::writeNullFlag(bool isNull)

void BasicCodec::writeCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, funPtr callback)
{
assert(callbacksCount > 1);
uint8_t i;

assert(callbacksCount > 1U);

// callbacks = callbacks table
for (uint8_t i = 0; i < callbacksCount; i++)
for (i = 0; i < callbacksCount; i++)
{
if (callbacks[i] == callback)
{
write(i);
break;
}
if (i + 1 == callbacksCount)
if ((i + 1U) == callbacksCount)
{
updateStatus(kErpcStatus_UnknownCallback);
}
Expand All @@ -170,18 +176,19 @@ void BasicCodec::writeCallback(funPtr callback1, funPtr callback2)
void BasicCodec::startReadMessage(message_type_t *type, uint32_t *service, uint32_t *request, uint32_t *sequence)
{
uint32_t header;

read(&header);

if (((header >> 24) & 0xff) != kBasicCodecVersion)
if (((header >> 24) & 0xffU) != kBasicCodecVersion)
{
updateStatus(kErpcStatus_InvalidMessageVersion);
}

if (!m_status)
{
*service = ((header >> 16) & 0xff);
*request = ((header >> 8) & 0xff);
*type = static_cast<message_type_t>(header & 0xff);
*service = ((header >> 16) & 0xffU);
*request = ((header >> 8) & 0xffU);
*type = static_cast<message_type_t>(header & 0xffU);

read(sequence);
}
Expand All @@ -205,6 +212,7 @@ void BasicCodec::readData(void *value, uint32_t length)
void BasicCodec::read(bool *value)
{
uint8_t v = 0;

readData(&v, sizeof(v));
if (!m_status)
{
Expand Down Expand Up @@ -265,6 +273,7 @@ void BasicCodec::read(double *value)
void BasicCodec::readPtr(uintptr_t *value)
{
uint8_t ptrSize;

read(&ptrSize);

if (ptrSize > sizeof(*value))
Expand Down Expand Up @@ -311,7 +320,8 @@ void BasicCodec::startReadList(uint32_t *length)
{
// Read list length as u32.
read(length);
if (m_status)

if (!isStatusOk())
{
*length = 0;
}
Expand All @@ -326,20 +336,23 @@ void BasicCodec::startReadUnion(int32_t *discriminator)
void BasicCodec::readNullFlag(bool *isNull)
{
uint8_t flag;

read(&flag);
if (!m_status)
if (isStatusOk())
{
*isNull = (flag == kIsNull);
*isNull = (flag == (uint8_t)kIsNull);
}
}

void BasicCodec::readCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, funPtr *callback)
{
assert(callbacksCount > 1);
// callbacks = callbacks table
uint8_t _tmp_local;

assert(callbacksCount > 1U);

// callbacks = callbacks table
read(&_tmp_local);
if (!m_status)
if (isStatusOk())
{
if (_tmp_local < callbacksCount)
{
Expand Down
Loading