-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
MISRA C Do not use recursions #11425
Comments
@andyross if you have time can you take a look on this ? |
MISRA exists just to make my life miserable, doesn't it? (FWIW: I know of at least one other in mempool, though that one is proper tail recursion and maybe MISRA has an exception for that?) Yeah, I'll take it. FWIW: there is a non-recursive walker (a FOREACH kind of thing), but it's got significantly higher code size. |
it does feel to be in my shoes :) Yeah, I'm sorry for that, I know that not using recursion here will increase and make it more complicated. |
Everyone's.
I'm sure tail recursion doesn't exist in MISRA's world. And speaking seriously, C doesn't guarantee tail-recursive optimization, so... just don't tell anyone there's another func like that ;-). |
Actually looking at this more carefully, this should be doable for 1.14. The two spots I know of are rb_walk above, and a tail recursion case in mempool. The latter can be turned into iteration with 2-3 lines of code and an extra level of indentation, and it turns out the former is in fact no longer used in the tree beyond the test case (I needed it in the scheduler at one point, but I don't think that usage ever even merged). Will submit a patch. |
MISRA rules (see zephyrproject-rtos#11425) forbid recursive algorithms. In the case of rb_walk(), it's not actually used anywhere but a test right now, so we can simply disable the API when CONFIG_MISRA_SANE is defined. Mempool had a (IMHO, fairly clever) tail recursive loop in bfree_recombine() which can be trivially transformed into an only slightly uglier iterative version. Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
MISRA rules (see #11425) forbid recursive algorithms. In the case of rb_walk(), it's not actually used anywhere but a test right now, so we can simply disable the API when CONFIG_MISRA_SANE is defined. Mempool had a (IMHO, fairly clever) tail recursive loop in bfree_recombine() which can be trivially transformed into an only slightly uglier iterative version. Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Merged the recursion patch. Closing. |
MISRA-C does not allows that a function call themselves, either directly or indirectly. Currently there is only one spot in Zephyr doing it
_rb_walk()
.rule 17.2
part of: #9552
The text was updated successfully, but these errors were encountered: