diff --git a/src/guacd/connection.c b/src/guacd/connection.c index a5b98adfa2..1bb99dc086 100644 --- a/src/guacd/connection.c +++ b/src/guacd/connection.c @@ -67,13 +67,14 @@ static int __write_all(int fd, char* buffer, int length) { /* Repeatedly write() until all data is written */ - while (length > 0) { + int remaining_length = length; + while (remaining_length > 0) { - int written = write(fd, buffer, length); + int written = write(fd, buffer, remaining_length); if (written < 0) return -1; - length -= written; + remaining_length -= written; buffer += written; }