fixed possible integer underflow

fixes CID 443646, thanks coverety scan

(cherry picked from commit 007230711693cf12ae59a8439f22399f9727cb24)
This commit is contained in:
Frank Morgner
2024-09-09 15:58:34 +02:00
committed by Christoph Honal
parent 238ace8c46
commit 1df8faa540

View File

@@ -64,12 +64,12 @@ static SOCKET connectsock(const char *hostname, unsigned short port);
ssize_t sendall(SOCKET sock, const void *buffer, size_t size) ssize_t sendall(SOCKET sock, const void *buffer, size_t size)
{ {
size_t sent; size_t sent = 0;
ssize_t r; ssize_t r;
/* FIXME we should actually check the length instead of simply casting from /* FIXME we should actually check the length instead of simply casting from
* size_t to ssize_t (or int), which have both the same width! */ * size_t to ssize_t (or int), which have both the same width! */
for (sent = 0; sent < size; sent += r) { while (sent < size) {
r = send(sock, (void *) (((unsigned char *) buffer)+sent), r = send(sock, (void *) (((unsigned char *) buffer)+sent),
#ifdef _WIN32 #ifdef _WIN32
(int) (int)
@@ -78,6 +78,8 @@ ssize_t sendall(SOCKET sock, const void *buffer, size_t size)
if (r < 0) if (r < 0)
return r; return r;
sent += r;
} }
return (ssize_t) sent; return (ssize_t) sent;