Merge pull request #1391 from esnet/cjson_update_fix

Update for cjson for compile fix
This commit is contained in:
swlars 2022-09-23 11:17:14 -07:00 committed by GitHub
commit 81e90414de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 14 deletions

View File

@ -37,6 +37,7 @@
#pragma warning (disable : 4001)
#endif
#include "iperf_config.h"
#include <string.h>
#include <stdio.h>
#include <math.h>
@ -61,7 +62,6 @@
#endif
#include "cjson.h"
#include "iperf_config.h"
/* define our own boolean type */
#ifdef true
@ -90,6 +90,18 @@
#endif
#endif
#if defined(HAVE_INTTYPES_H)
# include <inttypes.h>
#else
# ifndef PRIu64
# if sizeof(long) == 8
# define PRIu64 "lu"
# else
# define PRIu64 "llu"
# endif
# endif
#endif
typedef struct {
const unsigned char *json;
size_t position;
@ -381,7 +393,7 @@ loop_end:
}
else
{
item->valueint = (int)number;
item->valueint = (int64_t)number;
}
item->type = cJSON_Number;
@ -403,7 +415,7 @@ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number)
}
else
{
object->valueint = (int)number;
object->valueint = (int64_t)number;
}
return object->valuedouble = number;
@ -464,9 +476,9 @@ static unsigned char* ensure(printbuffer * const p, size_t needed)
return NULL;
}
if (needed > LLONG_MAX)
if (needed > SIZE_MAX)
{
/* sizes bigger than INT_MAX are currently not supported */
/* sizes bigger than SIZE_MAX are currently not supported */
return NULL;
}
@ -481,12 +493,12 @@ static unsigned char* ensure(printbuffer * const p, size_t needed)
}
/* calculate new buffer size */
if (needed > (LLONG_MAX / 2))
if (needed > (SIZE_MAX / 2))
{
/* overflow of int, use LLONG_MAX if possible */
if (needed <= LLONG_MAX)
/* overflow of int, use SIZE_MAX if possible */
if (needed <= SIZE_MAX)
{
newsize = LLONG_MAX;
newsize = SIZE_MAX;
}
else
{
@ -574,10 +586,10 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out
{
length = sprintf((char*)number_buffer, "null");
}
else if(d == (double)item->valueint)
{
length = sprintf((char*)number_buffer, "%ld", item->valueint);
}
else if(d == (double)item->valueint)
{
length = sprintf((char*)number_buffer, "%" PRIu64, item->valueint);
}
else
{
/* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */
@ -2457,7 +2469,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num)
}
else
{
item->valueint = (int)num;
item->valueint = (int64_t)num;
}
}

View File

@ -23,6 +23,10 @@
#ifndef cJSON__h
#define cJSON__h
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#ifdef __cplusplus
extern "C"
{