Skip to content

Commit b33162d

Browse files
authored
unix: fix use of uninitialized variable (libuv#4924)
The `flags` argument to `uv__udp_recvmsg_errqueue` was not initialized in all code paths. Shuffle code around to make the control flow more obvious (at the cost of a less legible diff.) Also fixes an unused label warning when building on systems that aren't Linux. Introduced last month in commit 80a5e3b, "linux: add MSG_ERRQUEUE ipv4/ipv6 udp support".
1 parent 12d1ed1 commit b33162d

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

src/unix/udp.c

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -326,39 +326,29 @@ static void uv__udp_recvmsg(uv_udp_t* handle, int flag) {
326326
}
327327
#endif
328328

329-
do {
329+
do
330330
nread = recvmsg(handle->io_watcher.fd, &h, flag);
331-
}
332331
while (nread == -1 && errno == EINTR);
333332

334-
if (nread == -1) {
335-
#if defined(__linux__)
336-
if ((flag & MSG_ERRQUEUE) &&
337-
uv__udp_recvmsg_errqueue(handle, &h, &buf,
338-
(const struct sockaddr*) &peer, flags)) {
339-
goto out;
340-
}
341-
#endif
342-
if (errno == EAGAIN || errno == EWOULDBLOCK)
343-
handle->recv_cb(handle, 0, &buf, NULL, 0);
344-
else
345-
handle->recv_cb(handle, UV__ERR(errno), &buf, NULL, 0);
346-
}
347-
else {
348-
flags = 0;
333+
flags = 0;
334+
if (nread != -1)
349335
if (h.msg_flags & MSG_TRUNC)
350336
flags |= UV_UDP_PARTIAL;
351337

352338
#if defined(__linux__)
353-
if ((flag & MSG_ERRQUEUE) &&
354-
uv__udp_recvmsg_errqueue(handle, &h, &buf,
355-
(const struct sockaddr*) &peer, flags)) {
356-
goto out;
357-
}
358-
#endif
359-
handle->recv_cb(handle, nread, &buf, (const struct sockaddr*) &peer, flags);
339+
if ((flag & MSG_ERRQUEUE) &&
340+
uv__udp_recvmsg_errqueue(handle, &h, &buf, (void*) &peer, flags)) {
341+
count--;
342+
continue;
360343
}
361-
out:
344+
#endif
345+
346+
if (nread != -1)
347+
handle->recv_cb(handle, nread, &buf, (void*) &peer, flags);
348+
else if (errno == EAGAIN || errno == EWOULDBLOCK)
349+
handle->recv_cb(handle, 0, &buf, NULL, 0);
350+
else
351+
handle->recv_cb(handle, UV__ERR(errno), &buf, NULL, 0);
362352
count--;
363353
}
364354
/* recv_cb callback may decide to pause or close the handle */

0 commit comments

Comments
 (0)