From 810bb89bdd454a96e12183c2b18a43c729aa5b57 Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Tue, 16 Feb 2021 01:01:30 +0100 Subject: cjson: upgrade to new version See if this fixes the coverity issues. Now at 324a6ac9a9b285ff7a5a3e5b2071e3624b94f2db Type: fix Signed-off-by: Ole Troan Change-Id: I2cd281ebaeda69e214e6dc93a84888298741d0ee Signed-off-by: Ole Troan --- src/vppinfra/cJSON.c | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'src/vppinfra') diff --git a/src/vppinfra/cJSON.c b/src/vppinfra/cJSON.c index 4c6a308eece..5b26a4be4e1 100644 --- a/src/vppinfra/cJSON.c +++ b/src/vppinfra/cJSON.c @@ -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. */ @@ -78,8 +78,12 @@ #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; } -- cgit 1.2.3-korg