summaryrefslogtreecommitdiff
path: root/tests/lib/test_printfrr.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2021-03-02 20:16:18 +0100
committerDavid Lamparter <equinox@diac24.net>2021-03-27 17:01:29 +0100
commit487eefcfbec8a24d639e6b8c805540d5c1fe38e8 (patch)
tree49b095d2ebf319223532bd5da12f3ef641450d34 /tests/lib/test_printfrr.c
parenteba599a39756b3d9424467f1e1f4f4475dffad17 (diff)
lib: record output positions in printfrr
This replaces `%n` with a safe, out-of-band option that simply records the start and end offset of the output produced for each `%...` specifier. The old `%n` code is removed. Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'tests/lib/test_printfrr.c')
-rw-r--r--tests/lib/test_printfrr.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/tests/lib/test_printfrr.c b/tests/lib/test_printfrr.c
index 9ffea8b978..6d64615faf 100644
--- a/tests/lib/test_printfrr.c
+++ b/tests/lib/test_printfrr.c
@@ -95,11 +95,21 @@ static void printchk(const char *ref, const char *fmt, ...)
errors++;
}
+ struct fmt_outpos outpos[16];
+ struct fbuf fb = {
+ .buf = bufrr,
+ .pos = bufrr,
+ .len = sizeof(bufrr) - 1,
+ .outpos = outpos,
+ .outpos_n = array_size(outpos),
+ };
+
va_start(ap, fmt);
- vsnprintfrr(bufrr, sizeof(bufrr), fmt, ap);
+ vbprintfrr(&fb, fmt, ap);
+ fb.pos[0] = '\0';
va_end(ap);
- printf("fmt: \"%s\"\nref: \"%s\"\nfrr: \"%s\"\n%s\n\n",
+ printf("fmt: \"%s\"\nref: \"%s\"\nfrr: \"%s\"\n%s\n",
fmt, ref, bufrr, strcmp(ref, bufrr) ? "ERROR" : "ok");
if (strcmp(ref, bufrr))
errors++;
@@ -107,6 +117,14 @@ static void printchk(const char *ref, const char *fmt, ...)
printf("return value <> length mismatch\n");
errors++;
}
+
+ for (size_t i = 0; i < fb.outpos_i; i++)
+ printf("\t[%zu: %u..%u] = \"%.*s\"\n", i,
+ outpos[i].off_start,
+ outpos[i].off_end,
+ (int)(outpos[i].off_end - outpos[i].off_start),
+ bufrr + outpos[i].off_start);
+ printf("\n");
}
int main(int argc, char **argv)