Skip to content

Commit 0f417d6

Browse files
committed
Initialize errno variables and fix maybe-uninitialized warnings
1 parent 4099b04 commit 0f417d6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ext/socket/raddrinfo.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ rb_getaddrinfo(const char *hostp, const char *portp, const struct addrinfo *hint
481481
{
482482
int retry;
483483
struct getaddrinfo_arg *arg;
484-
int err, gai_errno;
484+
int err, gai_errno = 0;
485485

486486
start:
487487
retry = 0;
@@ -531,7 +531,7 @@ rb_getaddrinfo(const char *hostp, const char *portp, const struct addrinfo *hint
531531
/* Because errno is threadlocal, the errno value we got from the call to getaddrinfo() in the thread
532532
* (in case of EAI_SYSTEM return value) is not propagated to the caller of _this_ function. Set errno
533533
* explicitly, as round-tripped through struct getaddrinfo_arg, to deal with that */
534-
errno = gai_errno;
534+
if (gai_errno) errno = gai_errno;
535535
return err;
536536
}
537537

@@ -700,7 +700,7 @@ rb_getnameinfo(const struct sockaddr *sa, socklen_t salen,
700700
{
701701
int retry;
702702
struct getnameinfo_arg *arg;
703-
int err, gni_errno;
703+
int err, gni_errno = 0;
704704

705705
start:
706706
retry = 0;
@@ -750,7 +750,7 @@ rb_getnameinfo(const struct sockaddr *sa, socklen_t salen,
750750

751751
/* Make sure we copy the thread-local errno value from the getnameinfo thread back to this thread, so
752752
* calling code sees the correct errno */
753-
errno = gni_errno;
753+
if (gni_errno) errno = gni_errno;
754754
return err;
755755
}
756756

0 commit comments

Comments
 (0)