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

*: fix clang-19 SA #17136

Merged
merged 15 commits into from
Oct 17, 2024
Merged

*: fix clang-19 SA #17136

merged 15 commits into from
Oct 17, 2024

Conversation

eqvinox
Copy link
Contributor

@eqvinox eqvinox commented Oct 16, 2024

scan-build: Analysis run complete.
scan-build: Removing directory '/tmp/scan-build-2024-10-16-130506-210976-1' because it contains no reports.
scan-build: No bugs found.

Refer to individual commits for details.

Haven't checked random weird build configurations so there might still be an issue or two on different platforms and/or build options.

clang-19's SA complains about unused initializers for this kind of
"switch (enum) { return string }" kind of code.  Use direct string
return values to avoid the issue.

Signed-off-by: David Lamparter <[email protected]>
In these cases the value assigned by the switch block is used directly
rather than returned.  Mark the initial/default value as used so
clang-SA doesn't complain about it.

Signed-off-by: David Lamparter <[email protected]>
The flex-generated code is disabled for clang-SA builds already, but
that means that function prototypes are missing too.  Just add dummy
function prototypes so clang-SA can process the file.

Signed-off-by: David Lamparter <[email protected]>
clang-SA complains that ns->fd could be invalid.  Add a guard.

Signed-off-by: David Lamparter <[email protected]>
errno is only valid if there was an actual error.  A zero return value
isn't an error, it's either EOF or an empty datagram depending on
context.  Fix the logic.

Signed-off-by: David Lamparter <[email protected]>
clang-SA complains that it's only partially initialized (because it's
used with IPv4 only).  The code later calls some AF-generic code,
prompting clang-SA to complain that the non-IPv4 parts are used without
being set.  While this shouldn't happen, just initialize it fully.

Signed-off-by: David Lamparter <[email protected]>
The `buf` pointer is being updated as the parse goes along.  It's not
used after the last update, but I'd rather keep this in for consistency.
Just make a note of it being unused.

Signed-off-by: David Lamparter <[email protected]>
If a packet doesn't have an interface, we're gonna crash 2 lines below.
An assert is a little more useful... and makes clang-SA not complain
about it.

Signed-off-by: David Lamparter <[email protected]>
If a create-config command is received, but the config is never applied,
the config will be leaked on the next create-config command.  This
should theoretically never happen, but let's fix it anyway.

Signed-off-by: David Lamparter <[email protected]>
non-blocking retries are already handled in `vtysh_client_receive()`.
And by the point we're back in `vtysh_client_run()`, errno may have been
overwritten by the close() call in vtysh_client_receive().

Signed-off-by: David Lamparter <[email protected]>
While the logic here is perfectly fine, clang-SA doesn't understand that
the fopen() and fclose() match up with each other.  Just use a separate
variable to make clang-SA happy.

Signed-off-by: David Lamparter <[email protected]>
`FILE *` objects are theoretically in an invalid state if you try to use
them past their reporting EOF.  Adjust the code to make it correct.

Signed-off-by: David Lamparter <[email protected]>
`errno` has its own semantics.  Sometimes it is correct to write to it.
This is not one of those cases - just use a separate `nl_errno`.

Signed-off-by: David Lamparter <[email protected]>
`dirfd()` can theoretically return an error.  Call it once and check the
result.

clang-SA: technically correct™.  Ain't that the best kind of correct?

Signed-off-by: David Lamparter <[email protected]>
Sigh. clang-SA doesn't want you to call read() while holding a mutex.

Signed-off-by: David Lamparter <[email protected]>
@eqvinox
Copy link
Contributor Author

eqvinox commented Oct 16, 2024

checkpatch complains about strncpy in unrelated code / not touched by this PR. This PR is to fix clang-19 SA and nothing else.

@eqvinox
Copy link
Contributor Author

eqvinox commented Oct 16, 2024

On a sidenote, the only really ugly "fix" is this one b5f196c

If someone wants to go find a better way to go about this…

(I'd proceed as is anyway, just to get SA clean, we can always iterate in further PRs.)

@mwinter-osr mwinter-osr self-requested a review October 16, 2024 12:24
Copy link
Member

@mwinter-osr mwinter-osr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wait do not yet merge - need an extra day to debug CI with PR #17137
(Need to test for flag as error if additional error shows up)

(Flagging this as "request changes" to avoid accidental merge and will change once done)

Copy link
Member

@mwinter-osr mwinter-osr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests done. Ok to merge this PR now

@donaldsharp donaldsharp merged commit 466efab into FRRouting:master Oct 17, 2024
25 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants