aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/cJSON.c
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2021-02-16 01:01:30 +0100
committerNeale Ranns <neale@graphiant.com>2021-02-16 08:12:18 +0000
commit810bb89bdd454a96e12183c2b18a43c729aa5b57 (patch)
tree7f4c5499aadaae838a34597bbf32bbb60f364391 /src/vppinfra/cJSON.c
parentbad4766763d5ad80b1296c1455666b2589272044 (diff)
cjson: upgrade to new version
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>
Diffstat (limited to 'src/vppinfra/cJSON.c')
-rw-r--r--src/vppinfra/cJSON.c47
1 files changed, 33 insertions, 14 deletions
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;
}