Skip to content

Commit 0072307

Browse files
committed
fixed possible integer underflow
fixes CID 443646, thanks coverety scan
1 parent 0197f61 commit 0072307

File tree

1 file changed

+7
-5
lines changed
  • virtualsmartcard/src/vpcd

1 file changed

+7
-5
lines changed

virtualsmartcard/src/vpcd/vpcd.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,23 @@ static SOCKET connectsock(const char *hostname, unsigned short port);
6464

6565
ssize_t sendall(SOCKET sock, const void *buffer, size_t size)
6666
{
67-
size_t sent;
67+
size_t sent = 0;
6868
ssize_t r;
6969

7070
/* FIXME we should actually check the length instead of simply casting from
7171
* size_t to ssize_t (or int), which have both the same width! */
72-
for (sent = 0; sent < size; sent += r) {
72+
while (sent < size) {
7373
r = send(sock, (void *) (((unsigned char *) buffer)+sent),
7474
#ifdef _WIN32
7575
(int)
7676
#endif
7777
(size-sent), MSG_NOSIGNAL);
7878

79-
if (r < 0)
80-
return r;
81-
}
79+
if (r < 0)
80+
return r;
81+
82+
sent += r;
83+
}
8284

8385
return (ssize_t) sent;
8486
}

0 commit comments

Comments
 (0)