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

Unreachable code in posix OS_BinSemCreate_Impl #803

Closed
skliper opened this issue Feb 11, 2021 · 1 comment · Fixed by #804 or #774
Closed

Unreachable code in posix OS_BinSemCreate_Impl #803

skliper opened this issue Feb 11, 2021 · 1 comment · Fixed by #804 or #774
Milestone

Comments

@skliper
Copy link
Contributor

skliper commented Feb 11, 2021

Is your feature request related to a problem? Please describe.
Can't reach:

if (cond_created)
{
pthread_cond_destroy(&(sem->cv));
}

Describe the solution you'd like
Refactor to eliminate dead code.

Describe alternatives you've considered
None

Additional context
Static analysis warning

Requester Info
Jacob Hageman - NASA/GSFC

@jphickey
Copy link
Contributor

This a matter of order-of-operations - nothing can currently fail after the condition var is created, but that's just the current form.

Although unreachable right now if something gets added in the future (e.g. setting an attribute or something after the cond was created) then this will become relevant/possible to reach this again. So I wouldn't necessarily recommend removing this - as it is a bit of future-proofing - a change elsewhere in the function can easily make it reachable again.

Rather than removing I would suggest adding something else - such as a "test" call to pthread_cond_signal() - and check the status (should always be successful on a cond var that was just created, and a no-op because nothing is pending). So this should always succeed, but it will provide a theoretical path where the cleanup has to do both - so it won't be flagged as unreachable anymore.

skliper added a commit to skliper/osal that referenced this issue Feb 11, 2021
@astrogeco astrogeco added this to the 6.0.0 milestone Feb 12, 2021
astrogeco added a commit that referenced this issue Feb 12, 2021
Fix #803, Add check of semaphore to avoid unreachable code in posix OS_BinSemCreate_Impl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants