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

lib: libc: minimal: add check on returned value #32993

Merged
merged 1 commit into from
Mar 23, 2021
Merged

lib: libc: minimal: add check on returned value #32993

merged 1 commit into from
Mar 23, 2021

Conversation

gudnimg
Copy link
Contributor

@gudnimg gudnimg commented Mar 5, 2021

The Coverity complains about sys_mutex_lock() which returns 0 if
locked. I added also the same check on returned value for
sys_mutex_unlock() which returns 0 if unlocked.

Signed-off-by: Guðni Már Gilbert gudni.m.g@gmail.com

@gudnimg gudnimg requested a review from nashif as a code owner March 5, 2021 16:48
@github-actions github-actions bot added the area: C Library C Standard Library label Mar 5, 2021
@gudnimg
Copy link
Contributor Author

gudnimg commented Mar 5, 2021

I'm wondering how we could track the returned value from sys_mutex_lock() and sys_mutex_unlock(). Could we use the errno variable?

Something like this: https://github.com/zephyrproject-rtos/zephyr/blob/ee79143ec80b1f9e83ab25d74a654517e214f303/lib/libc/minimal/source/stdlib/malloc.c#L51

Also, is there any advantage in using a macro CHECKIF() instead of if() directly?

Fix #32938 [Coverity CID :219508] "Unchecked return value in
lib/libc/minimal/source/stdlib/malloc.c"

The Coverity complains about sys_mutex_lock() which returns 0 if
locked. I added also the same check on returned value for
sys_mutex_unlock() which returns 0 if unlocked.

Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
@gudnimg
Copy link
Contributor Author

gudnimg commented Mar 5, 2021

Added a (void) cast to sys_mutex_unlock() in free() to make it clear we are not interested in the returned value. Hopefully that will be enough to supress a false alarm Coverity report.

@gudnimg
Copy link
Contributor Author

gudnimg commented Mar 17, 2021

@nashif friendly reminder :) do you know of anyone else to review this so we can proceed with the fix?

@carlescufi carlescufi merged commit 952970d into zephyrproject-rtos:master Mar 23, 2021
@gudnimg gudnimg deleted the gudni-lib-fix branch March 23, 2021 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: C Library C Standard Library
Projects
None yet
4 participants