-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
lib: fix compiler warnings (gcc) #13643
Closed
Closed
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
Seen when setting `-DDEBUGBUILD` for mingw-w64 gcc 13.2.0 CMake unity builds in 'Release' configurations. ``` curl/lib/curl_gethostname.c:71:5: error: 'strncpy' specified bound 1025 equals destination size [-Werror=stringop-truncation] 71 | strncpy(name, force_hostname, namelen); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from curl/_bld/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c:175: In function 'hostcache_timestamp_remove', inlined from 'Curl_hash_clean_with_criterium' at curl/lib/hash.c:265:19, inlined from 'Curl_hash_clean_with_criterium' at curl/lib/hash.c:247:1, inlined from 'hostcache_prune' at curl/lib/hostip.c:228:3, inlined from 'Curl_hostcache_prune' at curl/lib/hostip.c:256:21: curl/lib/hostip.c:205:12: error: 'now' may be used uninitialized [-Werror=maybe-uninitialized] 205 | time_t age = prune->now - c->timestamp; | ^~~ curl/lib/hostip.c: In function 'Curl_hostcache_prune': curl/lib/hostip.c:241:10: note: 'now' was declared here 241 | time_t now; | ^~~ In function 'hostcache_timestamp_remove', inlined from 'fetch_addr' at curl/lib/hostip.c:310:8: curl/lib/hostip.c:205:23: error: 'user.now' may be used uninitialized [-Werror=maybe-uninitialized] 205 | time_t age = prune->now - c->timestamp; | ~~~~~^~~~~ curl/lib/hostip.c: In function 'fetch_addr': curl/lib/hostip.c:304:33: note: 'user' declared here 304 | struct hostcache_prune_data user; | ^~~~ In file included from curl/_bld/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c:40: curl/lib/cf-socket.c: In function 'cf_socket_send': curl/lib/cf-socket.c:1294:10: error: 'c' may be used uninitialized [-Werror=maybe-uninitialized] 1294 | if(c >= ((100-ctx->wblock_percent)*256/100)) { | ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ curl/lib/cf-socket.c:1292:19: note: 'c' was declared here 1292 | unsigned char c; | ^ In file included from curl/_bld/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c:364: In function 'tftp_state_timeout', inlined from 'tftp_multi_statemach' at curl/lib/tftp.c:1230:27: curl/lib/tftp.c:1208:5: error: 'current' may be used uninitialized [-Werror=maybe-uninitialized] 1208 | if(current > state->rx_time + state->retry_time) { | ^ curl/lib/tftp.c: In function 'tftp_multi_statemach': curl/lib/tftp.c:1192:10: note: 'current' was declared here 1192 | time_t current; | ^~~~~~~ ``` Ref: https://ci.appveyor.com/project/curlorg/curl/builds/49792835/job/91c8dj5qb36spfe0#L112 Ref: https://github.com/curl/curl/actions/runs/9082968838/job/24960616145#step:12:62 Ref: curl#13592 Closes curl#13643
d108dbf
to
ada22c8
Compare
This was referenced May 15, 2024
bagder
reviewed
May 16, 2024
vszakats
added a commit
to vszakats/curl
that referenced
this pull request
May 28, 2024
Following up on previous occurrences showing up as gcc warnings, replace the remaining few `time(&var)` calls with `= time(NULL)`, though these aren't specifically causing compiler warnings. All of these are in the TFTP client code (`lib/tftp.c`), except one which is in a debug branch in `lib/http_aws_sigv4`. What's unexplainable is that this patch seems to stabilize the TFTP tests regularly hanging or going into an infinite loop on GHA windows workflows with MSYS2, mingw-w64 and MSVC (Cygwin is unaffected): curl#13599 (comment) I figure it's something worth trying even if it turns out to be a dead end. `time()` docs: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/time-time32-time64 https://manpages.debian.org/bookworm/manpages-dev/time.2.en.html Follow-up to 58ca0a2 curl#13800 Follow-up to d0728c9 curl#13643 Closes #xxxxx
vszakats
added a commit
that referenced
this pull request
May 29, 2024
Following up on previous occurrences showing up as gcc warnings, replace the remaining `time(&var)` calls with `var = time(NULL)`, though these aren't specifically causing compiler warnings. These are in the TFTP client code (`lib/tftp.c`), except one which is in a debug branch in `lib/http_aws_sigv4.c`. What's unexplainable is that this patch seems to mitigate TFTP tests often hanging or going into an infinite loop on GHA windows workflows with MSYS2, mingw-w64 and MSVC (Cygwin is unaffected): #13599 (comment) TFTP hangs did not entirely disappear though, so could be unrelated. `time()` docs: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/time-time32-time64 https://manpages.debian.org/bookworm/manpages-dev/time.2.en.html Follow-up to 58ca0a2 #13800 Follow-up to d0728c9 #13643 Closes #13815
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.
Seen when setting
ENABLE_DEBUG=ON
and-DDEBUGBUILD
for mingw-w64gcc 13.2.0 CMake unity builds in 'Release' configurations.
Ref: https://ci.appveyor.com/project/curlorg/curl/builds/49792835/job/91c8dj5qb36spfe0#L112
Ref: https://github.com/curl/curl/actions/runs/9082968838/job/24960616145#step:12:62
Ref: #13592
Closes #13643