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 build flags and fix compilation warnings (gcc 14.1.0) #66

Merged
merged 18 commits into from
Aug 10, 2024

Conversation

f0rget-the-sad
Copy link
Contributor

@f0rget-the-sad f0rget-the-sad commented Jul 28, 2024

Current add_compile_options() in tests and examples are not taken into account, due to that any warnings are simply ignored.
This patch series moves add add_compile_options() before target creation to resolve this issue.

Also, I tried to group warnings fixes into categories as separate patches, so it should be possible to rearrange/replace part of them.

CPP_COMPILE is an option, a cache variable, thus regular unset() is not
working for it since it tries to unset the scope variable.

This causing cmake to skip compilation of rpc.
Unset CPP_COMPILE from CACHE to make it work as intended.
Currently tests, soak and examples are build without extra flags,
because add_compile_options is specified after defining build targets.

From add_compile_options() docs:
Adds options to the compiler command line for targets in the current
directory and below that are added *after* this command is invoked.
Fixes:
warning: ISO C forbids conversion of function pointer to object pointer
type
Nb net could be included multiple times, to prevent creation of global
variables in each file move them under NBNET_IMPL.

Also use designated initializer to initiate a driver structure to
remove warnings about partial initialization. Designated initializer
would initialize other members to zero.
Cast unused function arguments to (void) to suspend warnings.
Remove unnecessary lt 0 checks and sync types to remove signed vs
unsigned warnings.
Fixes:
nbnet/tests/string_tests.c:18:9: error: ‘strncpy’
output truncated before terminating nul copying 5 bytes from a string of
the same length
[-Werror=stringop-truncation]
   18 |         strncpy(res + pos, b, len_b);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

nbnet/tests/string_tests.c:24:9: error: ‘strncpy’
specified bound depends on the length of the source argument
[-Werror=stringop-truncation]
Mark GameServer_GetClientCount() as inline.
In case when value in unsigned type and min is 0, this commit just
obfuscates types, maybe there's better solution.

Fixes:
warning: comparison of unsigned expression in ‘>= 0’ is always true
[-Wtype-limits]
In release mode(-DCMAKE_BUILD_TYPE=Release) tests returning following
error:
nbnet/tests/../nbnet.h:2272:9: error: ‘memcpy’ forming offset [4, 7] is
out of the bound s [0, 4] of object ‘word’ with type ‘Word’ {aka
‘unsigned int’} [-Werror=array-bounds=]
 2272 |         memcpy(bytes, &word, length); |
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add check to verify that length is less than Word size.
@nathhB
Copy link
Owner

nathhB commented Aug 2, 2024

@f0rget-the-sad thank you for your contribution. According to the pipeline, it seems that the code does not compile on Windows anymore.

@nathhB nathhB merged commit 15d823d into nathhB:master Aug 10, 2024
18 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