[PATCH] tools: net: traceevent: Fix 'snprintf' return value check in 'tep_filter_strerror'

From: Fedor Tokarev
Date: Thu Oct 15 2020 - 10:30:16 EST


'snprintf' returns the number of characters which would have been written
if enough space had been available, excluding the terminating null byte.
Thus, the return value of 'buflen' means that the last character
was dropped.

Signed-off-by: Fedor Tokarev <ftokarev@xxxxxxxxx>
---
tools/lib/traceevent/parse-filter.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c
index c271aee..dccdbf2 100644
--- a/tools/lib/traceevent/parse-filter.c
+++ b/tools/lib/traceevent/parse-filter.c
@@ -1374,7 +1374,7 @@ int tep_filter_strerror(struct tep_event_filter *filter, enum tep_errno err,
if (strlen(filter->error_buffer) > 0) {
size_t len = snprintf(buf, buflen, "%s", filter->error_buffer);

- if (len > buflen)
+ if (len >= buflen)
return -1;
return 0;
}
--
2.7.4