cjson: upgrade to new version 03/31303/3
authorOle Troan <ot@cisco.com>
Tue, 16 Feb 2021 00:01:30 +0000 (01:01 +0100)
committerNeale Ranns <neale@graphiant.com>
Tue, 16 Feb 2021 08:12:18 +0000 (08:12 +0000)
See if this fixes the coverity issues.
Now at 324a6ac9a9b285ff7a5a3e5b2071e3624b94f2db

Type: fix
Signed-off-by: Ole Troan <ot@cisco.com>
Change-Id: I2cd281ebaeda69e214e6dc93a84888298741d0ee
Signed-off-by: Ole Troan <ot@cisco.com>
MAINTAINERS
src/vppinfra/cJSON.c

index 6003a81..35bdaa3 100644 (file)
@@ -728,6 +728,11 @@ M: neale@graphiant.com
 M:     Matthew Smith <mgsmith@netgate.com>
 F:     src/plugins/linux-cp/
 
+cJSON
+I:     cjson
+M:     Ole Troan <ot@cisco.com>
+F:     src/vppinfra/cJSON.[ch]
+
 THE REST
 I:     misc
 M:     vpp-dev Mailing List <vpp-dev@fd.io>
index 4c6a308..5b26a4b 100644 (file)
@@ -19,7 +19,7 @@
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   THE SOFTWARE.
 */
-
+/* clang-format off */
 /* cJSON */
 /* JSON parser in C. */
 
 #endif
 
 #ifndef NAN
+#ifdef _WIN32
+#define NAN sqrt (-1.0)
+#else
 #define NAN 0.0/0.0
 #endif
+#endif
 
 typedef struct {
     const unsigned char *json;
@@ -507,11 +511,9 @@ static unsigned char* ensure(printbuffer * const p, size_t needed)
 
             return NULL;
         }
-        if (newbuffer)
-        {
-            memcpy(newbuffer, p->buffer, p->offset + 1);
-        }
-        p->hooks.deallocate(p->buffer);
+
+       memcpy (newbuffer, p->buffer, p->offset + 1);
+       p->hooks.deallocate (p->buffer);
     }
     p->length = newsize;
     p->buffer = newbuffer;
@@ -2544,6 +2546,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count)
     }
 
     a = cJSON_CreateArray();
+
     for(i = 0; a && (i < (size_t)count); i++)
     {
         n = cJSON_CreateNumber(numbers[i]);
@@ -2562,7 +2565,11 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count)
         }
         p = n;
     }
-    a->child->prev = n;
+
+    if (a && a->child)
+      {
+       a->child->prev = n;
+      }
 
     return a;
 }
@@ -2599,7 +2606,11 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count)
         }
         p = n;
     }
-    a->child->prev = n;
+
+    if (a && a->child)
+      {
+       a->child->prev = n;
+      }
 
     return a;
 }
@@ -2618,9 +2629,9 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count)
 
     a = cJSON_CreateArray();
 
-    for(i = 0;a && (i < (size_t)count); i++)
-    {
-        n = cJSON_CreateNumber(numbers[i]);
+    for (i = 0; a && (i < (size_t) count); i++)
+      {
+       n = cJSON_CreateNumber(numbers[i]);
         if(!n)
         {
             cJSON_Delete(a);
@@ -2635,8 +2646,12 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count)
             suffix_object(p, n);
         }
         p = n;
-    }
-    a->child->prev = n;
+      }
+
+    if (a && a->child)
+      {
+       a->child->prev = n;
+      }
 
     return a;
 }
@@ -2673,7 +2688,11 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int co
         }
         p = n;
     }
-    a->child->prev = n;
+
+    if (a && a->child)
+      {
+       a->child->prev = n;
+      }
 
     return a;
 }