libc: prevent compiler warning

This commit is contained in:
Christian Helmuth
2022-09-08 14:25:34 +02:00
committed by Norman Feske
parent 8186a1d7f8
commit 5b25060730

View File

@ -846,18 +846,19 @@ extern "C" ssize_t socket_fs_recvmsg(int libc_fd, msghdr *msg, int flags)
size_t numberOfBytes = 0; size_t numberOfBytes = 0;
char *data = nullptr; char *data = nullptr;
size_t length = 0; size_t length = 0;
size_t i;
char *buffer; char *buffer;
ssize_t res; ssize_t res;
size_t amount; size_t amount;
socklen_t client_address_len; socklen_t client_address_len;
/* iterate over all msg_iov to get the number of bytes that have to be read. */ /* iterate over all msg_iov to get the number of bytes that have to be read. */
for (i = 0; i < msg->msg_iovlen; i++) { for (int i = 0; i < msg->msg_iovlen; i++) {
numberOfBytes += msg->msg_iov[i].iov_len; numberOfBytes += msg->msg_iov[i].iov_len;
/* As an optimization, we set the initial values of DATA and LEN /*
from the first non-empty iovec. This kicks-in in the case * As an optimization, we set the initial values of DATA and LEN from
where the whole packet fits into the first iovec buffer. */ * the first non-empty iovec. This kicks-in in the case where the whole
* packet fits into the first iovec buffer.
*/
if (data == nullptr && msg->msg_iov[i].iov_len > 0) { if (data == nullptr && msg->msg_iov[i].iov_len > 0) {
data = (char*)msg->msg_iov[i].iov_base; data = (char*)msg->msg_iov[i].iov_base;
length = msg->msg_iov[i].iov_len; length = msg->msg_iov[i].iov_len;
@ -895,7 +896,7 @@ extern "C" ssize_t socket_fs_recvmsg(int libc_fd, msghdr *msg, int flags)
} else { } else {
amount = length; amount = length;
buffer = data; buffer = data;
for (i = 0; i < msg->msg_iovlen; i++) { for (int i = 0; i < msg->msg_iovlen; i++) {
#define min(a, b) ((a) > (b) ? (b) : (a)) #define min(a, b) ((a) > (b) ? (b) : (a))
size_t copy = min (msg->msg_iov[i].iov_len, amount); size_t copy = min (msg->msg_iov[i].iov_len, amount);
::memcpy (msg->msg_iov[i].iov_base, buffer, copy); ::memcpy (msg->msg_iov[i].iov_base, buffer, copy);