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

Enable all warnings and pedantic mode #78

Merged
merged 4 commits into from
Nov 25, 2024
Merged

Conversation

nirs
Copy link
Member

@nirs nirs commented Nov 20, 2024

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.

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

nirs and others added 4 commits November 23, 2024 04:57
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 AkihiroSuda merged commit 20c338d into lima-vm:master Nov 25, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants