(wrong string) ée

From: <git_AT_suckless.org>
Date: Sun, 15 Jan 2017 17:15:52 +0100 (CET)

commit d6c07e7fa021e13b5b9914cb15f13c711ecd387d
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Sun Jan 15 17:15:47 2017 +0100
Commit: Mattias Andrée <maandree_AT_kth.se>
CommitDate: Sun Jan 15 17:15:47 2017 +0100

    Use macros to write the head
    
    Signed-off-by: Mattias Andrée <maandree_AT_kth.se>

diff --git a/src/blind-concat.c b/src/blind-concat.c
index bea127a..f6fe504 100644
--- a/src/blind-concat.c
+++ b/src/blind-concat.c
_AT_@ -80,9 +80,7 @@ concat_to_file(int argc, char *argv[], char *output_file)
                 close(stream.fd);
         }
 
- sprintf(head, "%zu %zu %zu %s\n%cuivf%zn",
- stream.frames, stream.width, stream.height, stream.pixfmt, 0, &headlen);
-
+ SPRINTF_HEAD_ZN(head, stream.frames, stream.width, stream.height, stream.pixfmt, &headlen);
         ewriteall(fd, head, (size_t)headlen, output_file);
 
         data = mmap(0, size + (size_t)headlen, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
_AT_@ -131,8 +129,7 @@ concat_to_file_parallel(int argc, char *argv[], char *output_file, size_t jobs)
                 frames += streams[i].frames;
         }
 
- sprintf(head, "%zu %zu %zu %s\n%cuivf%zn",
- frames, streams->width, streams->height, streams->pixfmt, 0, &headlen);
+ SPRINTF_HEAD_ZN(head, frames, streams->width, streams->height, streams->pixfmt, &headlen);
 
         echeck_frame_size(streams->width, streams->height, streams->pixel_size, 0, output_file);
         frame_size = streams->width * streams->height * streams->pixel_size;
diff --git a/src/blind-from-image.c b/src/blind-from-image.c
index 7040038..0a3f767 100644
--- a/src/blind-from-image.c
+++ b/src/blind-from-image.c
_AT_@ -254,7 +254,7 @@ after_fork:
                 eprintf("%s\n", conv_fail_msg);
 
         if (!headless) {
- printf("1 %s %s xyza\n%cuivf", width, height, 0);
+ FPRINTF_HEAD(stdout, 1, width, height, "xyza");
                 efflush(stdout, "<stdout>");
         }
 
diff --git a/src/blind-from-text.c b/src/blind-from-text.c
index 68ea869..6717c99 100644
--- a/src/blind-from-text.c
+++ b/src/blind-from-text.c
_AT_@ -47,7 +47,7 @@ main(int argc, char *argv[])
                         eprintf("<stdin>: no input\n");
         }
         if (len && line[len - 1] == '\n')
- line[--len] = '\n';
+ line[--len] = '\0';
         if ((size_t)len + 6 > sizeof(stream.buf))
                 eprintf("<stdin>: head is too long\n");
         stream.fd = -1;
diff --git a/src/blind-from-video.c b/src/blind-from-video.c
index 178ab17..f164195 100644
--- a/src/blind-from-video.c
+++ b/src/blind-from-video.c
_AT_@ -258,7 +258,7 @@ main(int argc, char *argv[])
         }
 
         if (skip_length) {
- sprintf(head, "%zu %zu %zu %s\n%cuivf%zn", frames, width, height, "xyza", 0, &headlen);
+ SPRINTF_HEAD_ZN(head, frames, width, height, "xyza", &headlen);
                 ewriteall(outfd, head, (size_t)headlen, outfile);
         }
 
_AT_@ -273,7 +273,7 @@ main(int argc, char *argv[])
         frames = length / frame_size;
 
         if (!skip_length) {
- sprintf(head, "%zu %zu %zu %s\n%cuivf%zn", frames, width, height, "xyza", 0, &headlen);
+ SPRINTF_HEAD_ZN(head, frames, width, height, "xyza", &headlen);
                 ewriteall(outfd, head, (size_t)headlen, outfile);
                 data = mmap(0, length + (size_t)headlen, PROT_READ | PROT_WRITE, MAP_SHARED, outfd, 0);
                 memmove(data + headlen, data, length);
diff --git a/src/blind-rewrite-head.c b/src/blind-rewrite-head.c
index 1de8a29..9111485 100644
--- a/src/blind-rewrite-head.c
+++ b/src/blind-rewrite-head.c
_AT_@ -38,8 +38,7 @@ rewrite(struct stream *stream, int frames_auto)
         else if (stream->frames != frame_count)
                 eprintf("%s: frame count mismatch\n", stream->file);
 
- sprintf(head, "%zu %zu %zu %s\n%cuivf%zn",
- stream->frames, stream->width, stream->height, stream->pixfmt, 0, &headlen);
+ SPRINTF_HEAD_ZN(head, stream->frames, stream->width, stream->height, stream->pixfmt, &headlen);
 
         length = stream->frames * frame_size;
         if (length > (size_t)SSIZE_MAX || (size_t)headlen > (size_t)SSIZE_MAX - length)
diff --git a/src/stream.c b/src/stream.c
index a6e9692..2ad30ed 100644
--- a/src/stream.c
+++ b/src/stream.c
_AT_@ -113,8 +113,7 @@ enset_pixel_size(int status, struct stream *stream)
 void
 fprint_stream_head(FILE *fp, struct stream *stream)
 {
- fprintf(fp, "%zu %zu %zu %s\n%cuivf",
- stream->frames, stream->width, stream->height, stream->pixfmt, 0);
+ FPRINTF_HEAD(fp, stream->frames, stream->width, stream->height, stream->pixfmt);
 }
 
 
diff --git a/src/stream.h b/src/stream.h
index 027db4a..53b7113 100644
--- a/src/stream.h
+++ b/src/stream.h
_AT_@ -4,6 +4,18 @@
 
 #define STREAM_HEAD_MAX (3 * 3 * sizeof(size_t) + sizeof(((struct stream *)0)->pixfmt) + 10)
 
+#define SPRINTF_HEAD_ZN(BUF, FRAMES, WIDTH, HEIGHT, PIXFMT, LENP)\
+ sprintf(BUF, "%zu %zu %zu %s\n%cuivf%zn",\
+ FRAMES, WIDTH, HEIGHT, PIXFMT, 0, LENP)
+
+#define SPRINTF_HEAD(BUF, FRAMES, WIDTH, HEIGHT, PIXFMT)\
+ sprintf(BUF, "%zu %zu %zu %s\n%cuivf",\
+ FRAMES, WIDTH, HEIGHT, PIXFMT, 0)
+
+#define FPRINTF_HEAD(FP, FRAMES, WIDTH, HEIGHT, PIXFMT)\
+ fprintf(fp, "%zu %zu %zu %s\n%cuivf",\
+ FRAMES, WIDTH, HEIGHT, PIXFMT, 0)
+
 #define einit_stream(...) eninit_stream(1, __VA_ARGS__)
 #define eset_pixel_size(...) enset_pixel_size(1, __VA_ARGS__)
 #define eread_stream(...) enread_stream(1, __VA_ARGS__)
Received on Sun Jan 15 2017 - 17:15:52 CET

This archive was generated by hypermail 2.3.0 : Sun Jan 15 2017 - 17:24:19 CET