From 9e9aaf5f8def7b3cb18bb9378a5c583c645ada0c Mon Sep 17 00:00:00 2001 From: Vincent Chatelain Date: Sat, 19 Oct 2024 00:51:48 +0200 Subject: [PATCH] CO_ODinterface: fix unreachable statement (#548) Using a `break` after a `return` triggers warning 111 of Arm Compiler 5. To fix this warning while respecting MISRA rules, the return mechanism of OD_getSub() function was changed to only exit at the end. --- 301/CO_ODinterface.c | 52 ++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/301/CO_ODinterface.c b/301/CO_ODinterface.c index 605b88b..8b96115 100644 --- a/301/CO_ODinterface.c +++ b/301/CO_ODinterface.c @@ -182,13 +182,15 @@ OD_getSub(const OD_entry_t* entry, uint8_t subIndex, OD_IO_t* io, bool_t odOrig) return ODR_DEV_INCOMPAT; } + ODR_t ret = ODR_OK; OD_stream_t* stream = &io->stream; /* attribute, dataOrig and dataLength, depends on object type */ switch (entry->odObjectType & (uint8_t)ODT_TYPE_MASK) { case ODT_VAR: { if (subIndex > 0U) { - return ODR_SUB_NOT_EXIST; + ret = ODR_SUB_NOT_EXIST; + break; } CO_PROGMEM OD_obj_var_t* odo = entry->odObject; @@ -199,7 +201,8 @@ OD_getSub(const OD_entry_t* entry, uint8_t subIndex, OD_IO_t* io, bool_t odOrig) } case ODT_ARR: { if (subIndex >= entry->subEntriesCount) { - return ODR_SUB_NOT_EXIST; + ret = ODR_SUB_NOT_EXIST; + break; } CO_PROGMEM OD_obj_array_t* odo = entry->odObject; @@ -225,7 +228,8 @@ OD_getSub(const OD_entry_t* entry, uint8_t subIndex, OD_IO_t* io, bool_t odOrig) } } if (odo == NULL) { - return ODR_SUB_NOT_EXIST; + ret = ODR_SUB_NOT_EXIST; + break; } stream->attribute = odo->attribute; @@ -234,32 +238,34 @@ OD_getSub(const OD_entry_t* entry, uint8_t subIndex, OD_IO_t* io, bool_t odOrig) break; } default: { - return ODR_DEV_INCOMPAT; + ret = ODR_DEV_INCOMPAT; break; } } - /* Access data from the original OD location */ - if ((entry->extension == NULL) || odOrig) { - io->read = OD_readOriginal; - io->write = OD_writeOriginal; - stream->object = NULL; - } - /* Access data from extension specified by application */ - else { - io->read = (entry->extension->read != NULL) ? entry->extension->read : OD_readDisabled; - io->write = (entry->extension->write != NULL) ? entry->extension->write : OD_writeDisabled; - stream->object = entry->extension->object; + if (ret == ODR_OK) { + /* Access data from the original OD location */ + if ((entry->extension == NULL) || odOrig) { + io->read = OD_readOriginal; + io->write = OD_writeOriginal; + stream->object = NULL; + } + /* Access data from extension specified by application */ + else { + io->read = (entry->extension->read != NULL) ? entry->extension->read : OD_readDisabled; + io->write = (entry->extension->write != NULL) ? entry->extension->write : OD_writeDisabled; + stream->object = entry->extension->object; + } + + /* Reset stream data offset */ + stream->dataOffset = 0; + + /* Add informative data */ + stream->index = entry->index; + stream->subIndex = subIndex; } - /* Reset stream data offset */ - stream->dataOffset = 0; - - /* Add informative data */ - stream->index = entry->index; - stream->subIndex = subIndex; - - return ODR_OK; + return ret; } uint32_t