-
Notifications
You must be signed in to change notification settings - Fork 17
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
Enable all warnings and pedantic mode #78
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
AkihiroSuda
approved these changes
Nov 23, 2024
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.
Thanks
I'm not sure why this is considered a function without prototype, but in C function without arguments accept any number of arguments. In this case we want a function that does not accept arguments so we need to use (void). cli.c:64:26: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes] 64 | static void print_version() { puts(VERSION); } | ^ | void Signed-off-by: Nir Soffer <[email protected]>
This is a gnu extension reported as warning when using -Wall -Wextra -pedantic. Avoiding it is easy and more clear. main.c:167:51: warning: arithmetic on a pointer to void is a GNU extension [-Wgnu-pointer-arith] 167 | memcpy(src_mac, pdv[i].vm_pkt_iov[0].iov_base + 6, sizeof(src_mac)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ Signed-off-by: Nir Soffer <[email protected]>
We compare the listen() function pointer to 0 instead of the listen_fd. This "works" because it is an extension. Using -Wall -Wextra -pedantic reveals the error: main.c:456:14: warning: ordered comparison between pointer and zero ('int (*)(int, int)' and 'int') is an extension [-Wpedantic] 456 | if (listen >= 0) { | ~~~~~~ ^ ~ Fix to compare listen_fd, and use -1 since this is is the sentinel value meaning we failed to create the socket. Signed-off-by: Nir Soffer <[email protected]>
This can be an issue for portable code, but we build for single platform and single compiler, so we should be ok. Don't treat warnings as errors to reduced the chance that the build will fail on older macOS versions or future versions. Signed-off-by: Nir Soffer <[email protected]>
AkihiroSuda
approved these changes
Nov 25, 2024
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.
Using
-Wall -Wextra -pedantic
revealed 2 places we used compiler extensions, and one copy and paste error, comparing function pointer to 0. Fix the code an enable all warnings.This can be an issue for portable code, but we build for single platform and single compiler, so we should be ok.
Don't treat warnings as errors to reduced the chance that the build will fail on older macOS versions or future versions.