From 038b04d80a5d5667bd689f51132abc1a02fd9e19 Mon Sep 17 00:00:00 2001 From: Stephan Date: Mon, 28 Nov 2016 09:11:14 +0100 Subject: [PATCH] Take out len from condition check. Otherwise, the check is just undefined behaviour. gcc even takes out this check because len can never be zero if len does not wrap around. Found with -Wstrict-overflow=2 --- cJSON.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cJSON.c b/cJSON.c index 766e558..ded3c88 100644 --- a/cJSON.c +++ b/cJSON.c @@ -712,8 +712,9 @@ static char *print_string_ptr(const char *str, printbuffer *p) ptr = str; /* calculate additional space that is needed for escaping */ - while ((token = *ptr) && ++len) + while ((token = *ptr)) { + ++len; if (strchr("\"\\\b\f\n\r\t", token)) { len++; /* +1 for the backslash */