From 8365a69d9b77f0e3bd847dec23c7bd567bda2e75 Mon Sep 17 00:00:00 2001 From: Mikko Koivunalho Date: Sat, 15 Feb 2020 15:18:05 +0200 Subject: [PATCH] Correct function type of snprintf man snprintf: Upon successful return, these functions return the number of characters printed (excluding the null byte used to end output to strings). The functions snprintf() and vsnprintf() do not write more than size bytes (including the terminating null byte ('\0')). If the output was truncated due to this limit, then the return value is the number of characters (excluding the terminating null byte) which would have been written to the final string if enough space had been available. Thus, a return value of size or more means that the output was truncated. (See also below under NOTES.) If an output error is encountered, a negative value is returned. Signed-off-by: Mikko Koivunalho --- tests/check_check_master.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/check_check_master.c b/tests/check_check_master.c index 776a6920..aaf45f3f 100644 --- a/tests/check_check_master.c +++ b/tests/check_check_master.c @@ -934,7 +934,7 @@ void record_failure_line_num(int linenum) { size_t to_write; size_t written; - int result; + int result, chars_printed; char string[16]; /* @@ -943,12 +943,13 @@ void record_failure_line_num(int linenum) */ linenum += 1; - to_write = snprintf(string, sizeof(string), "%d\n", linenum); - if(to_write == 0) + chars_printed = snprintf(string, sizeof(string), "%d\n", linenum); + if(chars_printed <= 0 || (size_t) chars_printed >= sizeof(string)) { fprintf(stderr, "%s:%d: Error in call to snprintf:", __FILE__, __LINE__); exit(1); } + to_write = (size_t) chars_printed; if(line_num_failures == NULL) {