From b798490f772e85289b4056734558f121788de523 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sun, 14 Nov 2021 01:28:42 +0000 Subject: [PATCH] test-strxcpyx: check result of snprintf --- src/test/test-strxcpyx.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/test/test-strxcpyx.c b/src/test/test-strxcpyx.c index 4b6d8ebce30..c68fe3c0644 100644 --- a/src/test/test-strxcpyx.c +++ b/src/test/test-strxcpyx.c @@ -83,10 +83,13 @@ static void test_sd_event_code_migration(void) { char c[100 * DECIMAL_STR_MAX(unsigned) + 1], *p; unsigned i; size_t l; - int o; + int o, r; - for (i = o = 0; i < 100; i++) - o += snprintf(&b[o], sizeof(b) - o, "%u ", i); + for (i = o = 0; i < 100; i++) { + r = snprintf(&b[o], sizeof(b) - o, "%u ", i); + assert_se(r >= 0 && r < (int) sizeof(b) - o); + o += r; + } p = c; l = sizeof(c); -- 2.47.3