소스 검색

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
Stephan 8 년 전
부모
커밋
038b04d80a
1개의 변경된 파일2개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 1
      cJSON.c

+ 2 - 1
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 */