aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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;
}