I was not aware of the changes in MISRA-2023, thanks for informing me!
Also, that's great news to hear in case I ever want to go back to the automotive industry. :)
Re:Tidy First?
by WesolyKubeczek on Thursday January 11, 2024 @09:06AM
(#38952310)
Well, aren't early returns in guard clauses "recovery from abnormality"?
You could flex some language lawyering to define "abnormality"...
I believe that's exactly it. An exception to the single return rule to allow for guard clauses. Wording is maybe a little too obscure though.
I don't know.
Here is the only relevant example I found:
p = X_MALLOC(sizeof(*p) * NUM);
if (p == NULL) {
return (MEM_NOTHING);
}
...
X_FREE(p);
return (OK);
It's clearly abnormal.Something like a:
if (get_size(obj) == 0) {
return empty_case;
}
... do more complicated code here ...
return result;
does not feel "abnormal".
MISRA 2012, Rule 15.5: "Only one exit point should be defined in a function.", advisory - https://www.ibm.com/docs/en/rtr/9.0.0?topic=review-code-misr...
HN users cordenr and bfrog say it was dropped in MISRA 2023: https://news.ycombinator.com/item?id=38680587 and https://news.ycombinator.com/item?id=38704631 . Both in a recent thread on MISRA 2023 at https://news.ycombinator.com/item?id=38674158 .
FWIW, HN user FirmwareBurner in that thread links to the "Embedded System development Coding Reference guide" version 3.0 (2018) from the Software Reliability Enhancement Center, Japan at https://www.ipa.go.jp/publish/qv6pgp00000011mh-att/000065271... which says