-
Notifications
You must be signed in to change notification settings - Fork 195
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
Fixes for minor issues #380
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The protocol family (or domain) is handled as an int by the socket API. We were not being consistent when handling it in our code and leading to implicit type conversions from uint to int.
This function returns a NetplanDefType and -1 is not part of the enum variants.
wowlan is used as a variable of type int, see handle_wowlan() where we OR multiple variants of the enum NetplanWifiWowlanFlag and store it in netdef->wowlan, producing a value that might not be a variant of the enum.
All these options are reassigned few lines below with NETPLAN_TRISTATE_UNSET which is the correct value for this type.
We initialize them with unsigned int values such G_MAXUINT.
sizeof() produces a value of type size_t.
The pointer subtraction returns a signed value. In this case, it will never be negative but it's still an implicit conversion when we compare the result with out_size. It's still implicitly converting the type to size_t but at least we can see it clearly now.
The 'const' qualifier is ignored when used on function return types. Found by -Wextra.
Some structs initialization were missing members. Found by -Wextra.
Maybe this warning could just be disabled given the size of the diff, but it seems useful to know how many of our functions have parameters we never use. The attribute __unused is defined in 'util-internal.h'.
It will add -Wextra to the build flags. It will enable some important checks such as -Wsign-compare for example.
slyon
approved these changes
Jul 19, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, those are some very good catches.
It is tedious work to fix all those paper cuts, kudos for doing it and increasing the compiler warning level, to avoid such issues going forward!
lgtm.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Some of this issues were found when I tried to compile netplan as c++, some were found by increasing the warning level with
-Wextra
and some were found by me while fixing the issues found by the compiler.Some changes might seem unnecessary, specially the one annotating unused parameters with
__unused
. But I think they add some value.My motivation to increase the warning_level to 2 is to avoid problems like this:
It's unfortunate that it's only caught by the compiler by using
-Wextra
or explicitly using-Wsign-compare
(which is enabled by-Wextra
).Annotating the unused parameters with
__unused
at least makes us aware about the big number of function parameters we never use and, because it's annoying having this annotations, we might decide to get rid of them in the future.Some changes were made to improve consistency, for example, the g++ compiler found a couple of instances of the code below (which is accepted by a C compiler):
As the result of the expression is not a variant of the Values enum, it seems to me it doesn't make sense to store it in a variable of type enum Values.
Checklist
make check
successfully.make check-coverage
).