mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0dfcde04c | ||
|
|
1934059554 | ||
|
|
cc84a446be | ||
|
|
e58f7ec027 | ||
|
|
4bfb880093 |
@@ -7,7 +7,7 @@ project(cJSON C)
|
|||||||
|
|
||||||
set(PROJECT_VERSION_MAJOR 1)
|
set(PROJECT_VERSION_MAJOR 1)
|
||||||
set(PROJECT_VERSION_MINOR 4)
|
set(PROJECT_VERSION_MINOR 4)
|
||||||
set(PROJECT_VERSION_PATCH 3)
|
set(PROJECT_VERSION_PATCH 4)
|
||||||
set(CJSON_VERSION_SO 1)
|
set(CJSON_VERSION_SO 1)
|
||||||
set(CJSON_UTILS_VERSION_SO 1)
|
set(CJSON_UTILS_VERSION_SO 1)
|
||||||
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -10,7 +10,7 @@ UTILS_TEST_SRC = cJSON.c cJSON_Utils.c test_utils.c
|
|||||||
|
|
||||||
LDLIBS = -lm
|
LDLIBS = -lm
|
||||||
|
|
||||||
LIBVERSION = 1.4.3
|
LIBVERSION = 1.4.4
|
||||||
CJSON_SOVERSION = 1
|
CJSON_SOVERSION = 1
|
||||||
UTILS_SOVERSION = 1
|
UTILS_SOVERSION = 1
|
||||||
|
|
||||||
|
|||||||
17
cJSON.c
17
cJSON.c
@@ -47,7 +47,7 @@ CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
|
/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
|
||||||
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 4) || (CJSON_VERSION_PATCH != 3)
|
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 4) || (CJSON_VERSION_PATCH != 4)
|
||||||
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
|
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -253,13 +253,19 @@ static unsigned char* ensure(printbuffer * const p, size_t needed, const interna
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((p->length > 0) && (p->offset >= p->length))
|
||||||
|
{
|
||||||
|
/* make sure that offset is valid */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (needed > INT_MAX)
|
if (needed > INT_MAX)
|
||||||
{
|
{
|
||||||
/* sizes bigger than INT_MAX are currently not supported */
|
/* sizes bigger than INT_MAX are currently not supported */
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
needed += p->offset;
|
needed += p->offset + 1;
|
||||||
if (needed <= p->length)
|
if (needed <= p->length)
|
||||||
{
|
{
|
||||||
return p->buffer + p->offset;
|
return p->buffer + p->offset;
|
||||||
@@ -270,8 +276,7 @@ static unsigned char* ensure(printbuffer * const p, size_t needed, const interna
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* calculate new buffer size */
|
/* calculate new buffer size */
|
||||||
newsize = needed * 2;
|
if (newsize > (INT_MAX / 2))
|
||||||
if (newsize > INT_MAX)
|
|
||||||
{
|
{
|
||||||
/* overflow of int, use INT_MAX if possible */
|
/* overflow of int, use INT_MAX if possible */
|
||||||
if (needed <= INT_MAX)
|
if (needed <= INT_MAX)
|
||||||
@@ -283,6 +288,10 @@ static unsigned char* ensure(printbuffer * const p, size_t needed, const interna
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newsize = needed * 2;
|
||||||
|
}
|
||||||
|
|
||||||
if (hooks->reallocate != NULL)
|
if (hooks->reallocate != NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
7
cJSON.h
7
cJSON.h
@@ -31,7 +31,7 @@ extern "C"
|
|||||||
/* project version */
|
/* project version */
|
||||||
#define CJSON_VERSION_MAJOR 1
|
#define CJSON_VERSION_MAJOR 1
|
||||||
#define CJSON_VERSION_MINOR 4
|
#define CJSON_VERSION_MINOR 4
|
||||||
#define CJSON_VERSION_PATCH 3
|
#define CJSON_VERSION_PATCH 4
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
@@ -132,8 +132,9 @@ CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
|
|||||||
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
|
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
|
||||||
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
|
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
|
||||||
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
|
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
|
||||||
/* Render a cJSON entity to text using a buffer already allocated in memory with length buf_len. Returns 1 on success and 0 on failure. */
|
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
|
||||||
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buf, const int len, const cJSON_bool fmt);
|
/* NOTE: If you are printing numbers, the buffer hat to be 63 bytes bigger then the printed JSON (worst case) */
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
|
||||||
/* Delete a cJSON entity and all subentities. */
|
/* Delete a cJSON entity and all subentities. */
|
||||||
CJSON_PUBLIC(void) cJSON_Delete(cJSON *c);
|
CJSON_PUBLIC(void) cJSON_Delete(cJSON *c);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user