Skip to content

Commit d0728c9

Browse files
committed
lib: fix compiler warnings (gcc)
Seen when setting `ENABLE_DEBUG=ON` and `-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
1 parent fd0d2ed commit d0728c9

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

lib/cf-socket.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ static ssize_t cf_socket_send(struct Curl_cfilter *cf, struct Curl_easy *data,
12791279
#ifdef DEBUGBUILD
12801280
/* simulate network blocking/partial writes */
12811281
if(ctx->wblock_percent > 0) {
1282-
unsigned char c;
1282+
unsigned char c = 0;
12831283
Curl_rand(data, &c, 1);
12841284
if(c >= ((100-ctx->wblock_percent)*256/100)) {
12851285
CURL_TRC_CF(data, cf, "send(len=%zu) SIMULATE EWOULDBLOCK", orig_len);
@@ -1357,7 +1357,7 @@ static ssize_t cf_socket_recv(struct Curl_cfilter *cf, struct Curl_easy *data,
13571357
#ifdef DEBUGBUILD
13581358
/* simulate network blocking/partial reads */
13591359
if(cf->cft != &Curl_cft_udp && ctx->rblock_percent > 0) {
1360-
unsigned char c;
1360+
unsigned char c = 0;
13611361
Curl_rand(data, &c, 1);
13621362
if(c >= ((100-ctx->rblock_percent)*256/100)) {
13631363
CURL_TRC_CF(data, cf, "recv(len=%zu) SIMULATE EWOULDBLOCK", len);

lib/curl_gethostname.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int Curl_gethostname(char * const name, GETHOSTNAME_TYPE_ARG2 namelen)
6868
/* Override host name when environment variable CURL_GETHOSTNAME is set */
6969
const char *force_hostname = getenv("CURL_GETHOSTNAME");
7070
if(force_hostname) {
71-
strncpy(name, force_hostname, namelen);
71+
strncpy(name, force_hostname, namelen - 1);
7272
err = 0;
7373
}
7474
else {

lib/hostip.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ void Curl_hostcache_prune(struct Curl_easy *data)
244244
if(data->share)
245245
Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
246246

247-
time(&now);
247+
now = time(NULL);
248248

249249
do {
250250
/* Remove outdated and unused entries from the hostcache */
@@ -298,7 +298,7 @@ static struct Curl_dns_entry *fetch_addr(struct Curl_easy *data,
298298
/* See whether the returned entry is stale. Done before we release lock */
299299
struct hostcache_prune_data user;
300300

301-
time(&user.now);
301+
user.now = time(NULL);
302302
user.cache_timeout = data->set.dns_cache_timeout;
303303
user.oldest = 0;
304304

lib/tftp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ static timediff_t tftp_state_timeout(struct Curl_easy *data,
12041204
state->state = TFTP_STATE_FIN;
12051205
return 0;
12061206
}
1207-
time(&current);
1207+
current = time(NULL);
12081208
if(current > state->rx_time + state->retry_time) {
12091209
if(event)
12101210
*event = TFTP_EVENT_TIMEOUT;

0 commit comments

Comments
 (0)