diff options
author | Yclept Nemo <pscjtwjdjtAhnbjm/dpn> | 2018-06-23 11:09:26 -0400 |
---|---|---|
committer | Jan Ekström <jeebjp@gmail.com> | 2018-07-29 12:54:56 +0300 |
commit | 5532a3da1ee058443d3162582b601f19b59377c2 (patch) | |
tree | 8ecb20ebb23982cd563dc4a4fdbe512a2c3bb51b | |
parent | 112b3fa92266ab36dbffa2abf66034203f66b2ce (diff) | |
download | mpv-5532a3da1ee058443d3162582b601f19b59377c2.tar.bz2 mpv-5532a3da1ee058443d3162582b601f19b59377c2.tar.xz |
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.
-rw-r--r-- | stream/stream_file.c | 16 | ||||
-rw-r--r-- | stream/stream_smb.c | 16 |
2 files changed, 16 insertions, 16 deletions
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) diff --git a/stream/stream_smb.c b/stream/stream_smb.c index 822ffdbfb0..269974f18b 100644 --- a/stream/stream_smb.c +++ b/stream/stream_smb.c @@ -84,18 +84,18 @@ 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) { + int r = len; + int wr; + while (r > 0) { pthread_mutex_lock(&smb_lock); - r = smbc_write(p->fd,buffer,len); + wr = smbc_write(p->fd,buffer,r); pthread_mutex_unlock(&smb_lock); - if (r <= 0) + if (wr <= 0) return -1; - wr += r; - buffer += r; + r -= wr; + buffer += wr; } - return len; + return len - r; } static void close_f(stream_t *s){ |