summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
authorYclept Nemo <pscjtwjdjtAhnbjm/dpn>2018-06-23 11:09:26 -0400
committerJan Ekström <jeebjp@gmail.com>2018-07-29 12:59:03 +0300
commit0914da082f3a034d9b2d2524d4bc3067555d95d7 (patch)
tree15db507b0bafd2013f68abddb519296b721e7eff /stream
parent021bea159215347e7f3aaae6b87bcd83a3313cf2 (diff)
downloadmpv-0914da082f3a034d9b2d2524d4bc3067555d95d7.tar.bz2
mpv-0914da082f3a034d9b2d2524d4bc3067555d95d7.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.
Diffstat (limited to 'stream')
-rw-r--r--stream/stream_file.c16
-rw-r--r--stream/stream_smb.c16
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){