From 1808d64b772cf03bac159210f8692125c9a84606 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Mon, 1 Mar 2021 05:14:10 +0100 Subject: [PATCH] test: Fix pipe_feed() to allow checking fprintf format strings Warned-by: gcc -W --- test/fgetln.c | 8 ++++---- test/fparseln.c | 2 +- test/test-stream.c | 8 ++++++-- test/test-stream.h | 7 ++++++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/test/fgetln.c b/test/fgetln.c index d08fb3b..2eafa84 100644 --- a/test/fgetln.c +++ b/test/fgetln.c @@ -75,7 +75,7 @@ test_fgetln_single(void) size_t len; int i; - fp = pipe_feed("%s", (const void **)data_ascii, DATA_LINES); + fp = pipe_feed(PIPE_DATA_ASCII, (const void **)data_ascii, DATA_LINES); for (i = 0; i < DATA_LINES; i++) { char *str = fgetln(fp, &len); @@ -102,7 +102,7 @@ test_fgetln_multi(void) files[i].lines = reallocarray(NULL, LINE_COUNT, sizeof(char *)); files[i].lines[0] = str; files[i].lines[1] = str; - files[i].fp = pipe_feed("%s", files[i].lines, LINE_COUNT); + files[i].fp = pipe_feed(PIPE_DATA_ASCII, files[i].lines, LINE_COUNT); } for (l = 0; l < LINE_COUNT; l++) { @@ -139,7 +139,7 @@ test_fgetwln_single(void) size_t len; int i; - fp = pipe_feed("%ls", (const void **)data_wide, DATA_LINES); + fp = pipe_feed(PIPE_DATA_WIDE, (const void **)data_wide, DATA_LINES); for (i = 0; i < DATA_LINES; i++) { wchar_t *wstr; @@ -168,7 +168,7 @@ test_fgetwln_multi(void) files[i].lines = reallocarray(NULL, LINE_COUNT, sizeof(char *)); files[i].lines[0] = wstr; files[i].lines[1] = wstr; - files[i].fp = pipe_feed("%ls", files[i].lines, LINE_COUNT); + files[i].fp = pipe_feed(PIPE_DATA_WIDE, files[i].lines, LINE_COUNT); } for (l = 0; l < LINE_COUNT; l++) { diff --git a/test/fparseln.c b/test/fparseln.c index daff6bd..5d7898d 100644 --- a/test/fparseln.c +++ b/test/fparseln.c @@ -68,7 +68,7 @@ test_fparseln(const char **data_expect, int flags) FILE *fp; size_t i, len, lineno = 0; - fp = pipe_feed("%s", (const void **)data_test, TEST_LINES); + fp = pipe_feed(PIPE_DATA_ASCII, (const void **)data_test, TEST_LINES); for (i = 0; i < EXPECT_LINES; i++) { char *str = fparseln(fp, &len, &lineno, NULL, flags); diff --git a/test/test-stream.c b/test/test-stream.c index 849f419..0bbb641 100644 --- a/test/test-stream.c +++ b/test/test-stream.c @@ -27,12 +27,13 @@ #include #include #include +#include #include #include "test-stream.h" FILE * -pipe_feed(const char *fmt, const void **buf, int buf_nmemb) +pipe_feed(enum pipe_data_mode mode, const void **buf, int buf_nmemb) { FILE *fp; int rc; @@ -56,7 +57,10 @@ pipe_feed(const char *fmt, const void **buf, int buf_nmemb) assert(fp); for (line = 0; line < buf_nmemb; line++) { - rc = fprintf(fp, fmt, buf[line]); + if (mode == PIPE_DATA_ASCII) + rc = fprintf(fp, "%s", (const char *)buf[line]); + else + rc = fprintf(fp, "%ls", (const wchar_t *)buf[line]); assert(rc >= 0); } diff --git a/test/test-stream.h b/test/test-stream.h index cee4e60..8caf3fc 100644 --- a/test/test-stream.h +++ b/test/test-stream.h @@ -29,8 +29,13 @@ #include +enum pipe_data_mode { + PIPE_DATA_ASCII, + PIPE_DATA_WIDE, +}; + FILE * -pipe_feed(const char *fmt, const void **buf, int buf_nmemb); +pipe_feed(enum pipe_data_mode mode, const void **buf, int buf_nmemb); void pipe_close(FILE *fp);