(wrong string) ée

From: <git_AT_suckless.org>
Date: Tue, 2 May 2017 00:11:48 +0200 (CEST)

commit a2eb10b156eafd5fc900471dded83c78adc5d46d
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Tue May 2 00:08:33 2017 +0200
Commit: Mattias Andrée <maandree_AT_kth.se>
CommitDate: Tue May 2 00:08:33 2017 +0200

    Fix support for tiny frames in blind-reverse
    
    Signed-off-by: Mattias Andrée <maandree_AT_kth.se>

diff --git a/src/blind-reverse.c b/src/blind-reverse.c
index 0bbe766..69013bb 100644
--- a/src/blind-reverse.c
+++ b/src/blind-reverse.c
_AT_@ -18,7 +18,7 @@ to_stdout(struct stream *stream, size_t frame_size)
                 ptr = stream->frames * frame_size + stream->headlen;
                 end = ptr + frame_size;
                 while (ptr < end) {
- if (!(r = epread(stream->fd, buf, sizeof(buf), ptr, stream->file)))
+ if (!(r = epread(stream->fd, buf, MIN(sizeof(buf), end - ptr), ptr, stream->file)))
                                 eprintf("%s: file is shorter than expected\n", stream->file);
                         ptr += n = (size_t)r;
                         ewriteall(STDOUT_FILENO, buf, n, "<stdout>");
_AT_@ -35,6 +35,21 @@ elseek_set(int fd, off_t offset, const char *fname)
 }
 
 static void
+epread_frame(struct stream *stream, char *buf, off_t off, size_t n)
+{
+ stream->ptr = stream->xptr = 0;
+ elseek_set(stream->fd, off, stream->file);
+ eread_frame(stream, buf, n);
+}
+
+static void
+epwrite_frame(struct stream *stream, char *buf, off_t off, size_t n)
+{
+ elseek_set(stream->fd, off, stream->file);
+ ewriteall(stream->fd, buf, n, stream->file);
+}
+
+static void
 in_place(struct stream *stream, size_t frame_size)
 {
         size_t f, fm = stream->frames - 1;
_AT_@ -47,13 +62,12 @@ in_place(struct stream *stream, size_t frame_size)
         for (f = 0; f < stream->frames >> 1; f++) {
                 pa = f * frame_size + stream->headlen;
                 pb = (fm - f) * frame_size + stream->headlen;
- eread_frame(stream, bufa, frame_size);
- elseek_set(stream->fd, pb, stream->file);
- eread_frame(stream, bufb, frame_size);
- elseek_set(stream->fd, pb, stream->file);
- ewriteall(stream->fd, bufa, frame_size, stream->file);
- elseek_set(stream->fd, pa, stream->file);
- ewriteall(stream->fd, bufb, frame_size, stream->file);
+
+ epread_frame(stream, bufa, pa, frame_size);
+ epread_frame(stream, bufb, pb, frame_size);
+
+ epwrite_frame(stream, bufa, pb, frame_size);
+ epwrite_frame(stream, bufb, pa, frame_size);
         }
 
         free(bufa);
Received on Tue May 02 2017 - 00:11:48 CEST

This archive was generated by hypermail 2.3.0 : Tue May 02 2017 - 00:13:10 CEST