From 5532a3da1ee058443d3162582b601f19b59377c2 Mon Sep 17 00:00:00 2001 From: Yclept Nemo Date: Sat, 23 Jun 2018 11:09:26 -0400 Subject: stream_smb/stream_file: fix `write_buffer` Functions `write` and `smbc_write` are given a diminishing buffer of incorrect constant size. After partial writes, the code would do another write of the full original length, failing to subtract the amount already written. --- stream/stream_file.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'stream/stream_file.c') diff --git a/stream/stream_file.c b/stream/stream_file.c index 5cf63558f2..a905780b2d 100644 --- a/stream/stream_file.c +++ b/stream/stream_file.c @@ -121,16 +121,16 @@ static int fill_buffer(stream_t *s, char *buffer, int max_len) static int write_buffer(stream_t *s, char *buffer, int len) { struct priv *p = s->priv; - int r; - int wr = 0; - while (wr < len) { - r = write(p->fd, buffer, len); - if (r <= 0) + int r = len; + int wr; + while (r > 0) { + wr = write(p->fd, buffer, r); + if (wr <= 0) return -1; - wr += r; - buffer += r; + r -= wr; + buffer += wr; } - return len; + return len - r; } static int seek(stream_t *s, int64_t newpos) -- cgit v1.2.3