fixed possible integer underflow
fixes CID 443646, thanks coverety scan (cherry picked from commit 007230711693cf12ae59a8439f22399f9727cb24)
This commit is contained in:
committed by
Christoph Honal
parent
238ace8c46
commit
1df8faa540
@@ -64,21 +64,23 @@ static SOCKET connectsock(const char *hostname, unsigned short port);
|
||||
|
||||
ssize_t sendall(SOCKET sock, const void *buffer, size_t size)
|
||||
{
|
||||
size_t sent;
|
||||
size_t sent = 0;
|
||||
ssize_t r;
|
||||
|
||||
/* 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! */
|
||||
for (sent = 0; sent < size; sent += r) {
|
||||
while (sent < size) {
|
||||
r = send(sock, (void *) (((unsigned char *) buffer)+sent),
|
||||
#ifdef _WIN32
|
||||
(int)
|
||||
#endif
|
||||
(size-sent), MSG_NOSIGNAL);
|
||||
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
sent += r;
|
||||
}
|
||||
|
||||
return (ssize_t) sent;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user