Skip to content

[th/sd-event-assert-return] Avoid side effects for assert_return() resolving sd-event#13250

Closed
thom311 wants to merge 2 commits intosystemd:masterfrom
thom311:th/sd-event-assert-return
Closed

[th/sd-event-assert-return] Avoid side effects for assert_return() resolving sd-event#13250
thom311 wants to merge 2 commits intosystemd:masterfrom
thom311:th/sd-event-assert-return

Conversation

@thom311
Copy link
Contributor

@thom311 thom311 commented Aug 2, 2019

Coverity warns about this (in NetworkManager's fork of the code), and I think it's right to warn.

Even if it may be a non-issue, False-Positive warnings are still cumbersome because they keep attracting attention.

thom311 added 2 commits August 2, 2019 10:45
…solve(e), -ENOPKG)"

Coverity thinks that this is not right:

  CID 202431 (systemd#1 of 1): Side effect in assertion (ASSERT_SIDE_EFFECT)
  assignment_where_comparison_intended: Assignment e = event_resolve(e) has a side effect. This code will work differently in a non-debug build.

And that's correct: we must always resolve SD_EVENT_DEFAULT, regardless
of whether assertions are enabled.
…()) and event_resolve()

The checks are always the same. Add and use a macro.
@thom311
Copy link
Contributor Author

thom311 commented Aug 2, 2019

Hm, it seems assert_return() cannot be actually disabled, so I wonder what makes coverity think this is an assertion -- in the sense that the code is striped from non-debug builds? Is that just due to the name of the macro (or underlying function)?

Also, macro.h specially handles ifdef __COVERITY__, but for some reason the coverity builds of NetworkManager don't seem to honor that...

@thom311
Copy link
Contributor Author

thom311 commented Aug 2, 2019

This seems related: https://community.synopsys.com/s/question/0D534000046Yuzb/suppressing-assertsideeffect-for-functions-that-allow-for-sideeffects

We have actually very few Coverity warnings related to assert_return() and assert_se(). So, while we probably should convince Coverity somehow to not show this warning, in practice this patch would solve almost all warnings we have in this regard...

@keszybz
Copy link
Member

keszybz commented Aug 2, 2019

We have made attempts in the past to teach coverity that assert_se (as the name implies) is not like assert. There's something something coverity patterns, that should solve this, but nobody ever got them to work. I just close all those bugs for assert_se manually.

I'd much rather teach coverity that assert_se is OK...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants