aboutsummaryrefslogtreecommitdiffstats
path: root/src/stream.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-04-08 23:02:48 +0200
committerMattias Andrée <maandree@kth.se>2017-04-08 23:02:48 +0200
commit0804a80954bf9b8c11392d77a4933ec0a4ff635b (patch)
treed19ab7658b07089af643deba41ec73f696925e54 /src/stream.c
parentDocument memory requirements, minor style fixes, more use of BUFSIZ, fix warnings, and fix potential buffer overflow (diff)
downloadblind-0804a80954bf9b8c11392d77a4933ec0a4ff635b.tar.gz
blind-0804a80954bf9b8c11392d77a4933ec0a4ff635b.tar.bz2
blind-0804a80954bf9b8c11392d77a4933ec0a4ff635b.tar.xz
Add blind-translate and fix errors
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/stream.c')
-rw-r--r--src/stream.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/stream.c b/src/stream.c
index a54f7f0..63f92c6 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -161,7 +161,7 @@ encheck_frame_size(int status, size_t width, size_t height, size_t pixel_size, c
{
if (!check_frame_size(width, height, pixel_size))
enprintf(status, "%s: %s%svideo frame is too large\n",
- prefix ? prefix : "", (prefix && *prefix) ? " " : "", fname);
+ fname, prefix ? prefix : "", (prefix && *prefix) ? " " : "");
}
@@ -218,9 +218,10 @@ nprocess_each_frame_segmented(int status, struct stream *stream, int output_fd,
for (frame = 0; frame < stream->frames; frame++) {
for (n = frame_size; n; n -= r) {
- if (!enread_stream(status, stream, n))
+ if (stream->ptr < n && !enread_stream(status, stream, SIZE_MAX))
enprintf(status, "%s: file is shorter than expected\n", stream->file);
r = stream->ptr - (stream->ptr % stream->pixel_size);
+ r = r < n ? r : n;
(process)(stream, r, frame);
enwriteall(status, output_fd, stream->buf, r, output_fname);
memmove(stream->buf, stream->buf + r, stream->ptr -= r);
@@ -301,6 +302,8 @@ nprocess_multiple_streams(int status, struct stream *streams, size_t n_streams,
if (streams[i].ptr && streams[i].ptr < n)
n = streams[i].ptr;
}
+ if (n == SIZE_MAX)
+ break;
n -= n % streams->pixel_size;
process(streams, n_streams, n);
@@ -308,13 +311,14 @@ nprocess_multiple_streams(int status, struct stream *streams, size_t n_streams,
closed = SIZE_MAX;
for (i = 0; i < n_streams; i++) {
- memmove(streams[i].buf, streams[i].buf + n, streams[i].ptr -= n);
+ if (streams[i].ptr)
+ memmove(streams[i].buf, streams[i].buf + n, streams[i].ptr -= n);
if (streams[i].ptr < streams->pixel_size && streams[i].fd < 0 && closed == SIZE_MAX)
closed = i;
}
if (closed != SIZE_MAX) {
for (i = (j = closed) + 1; i < n_streams; i++)
- if (streams[i].ptr < streams->pixel_size && streams[i].fd < 0)
+ if (streams[i].ptr >= streams->pixel_size || streams[i].fd >= 0)
streams[j++] = streams[i];
n_streams = j;
}