Compare commits

..

6 Commits

Author SHA1 Message Date
Max Bruckner
981f59b163 Release Version 1.2.1 2017-01-30 19:36:36 +01:00
Max Bruckner
e4eadb9a81 Merge pull request #97 from DaveGamble/fix96-null-pointer-dereference
Fix potential null pointer dereference in cJSON_Utils
Fixes #96
2017-01-30 19:34:33 +01:00
Max Bruckner
ff0681e4fd Utils: PatchDetach: Check for invalid patch string 2017-01-30 19:30:16 +01:00
Max Bruckner
a2309a509d Utils: InplaceDecodePointerString: Check for NULL 2017-01-30 19:29:52 +01:00
Max Bruckner
c49ffbfba8 cJSON_Version: returns a version string
This is useful to programmatically find out the version of cJSON that
has been used (useful in case of scripting language bindings for
example).
2017-01-12 20:37:29 +01:00
Max Bruckner
e7533aa6f0 Put version information in the header
This is important so that it is always known which version of the
library is used, especially if the C and Header files have just been
copy pasted to another code base.
2017-01-12 20:35:13 +01:00
6 changed files with 38 additions and 7 deletions

View File

@@ -7,7 +7,7 @@ project(cJSON C)
set(PROJECT_VERSION_MAJOR 1)
set(PROJECT_VERSION_MINOR 2)
set(PROJECT_VERSION_PATCH 0)
set(PROJECT_VERSION_PATCH 1)
set(CJSON_VERSION_SO 1)
set(CJSON_UTILS_VERSION_SO 1)
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")

View File

@@ -10,7 +10,7 @@ UTILS_TEST_SRC = cJSON.c cJSON_Utils.c test_utils.c
LDLIBS = -lm
LIBVERSION = 1.2.0
LIBVERSION = 1.2.1
CJSON_SOVERSION = 1
UTILS_SOVERSION = 1

View File

@@ -58,6 +58,14 @@ const char *cJSON_GetErrorPtr(void)
return global_ep;
}
extern const char* cJSON_Version(void)
{
static char version[15];
sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, CJSON_VERSION_PATCH);
return version;
}
/* case insensitive strcmp */
static int cJSON_strcasecmp(const char *s1, const char *s2)
{

View File

@@ -28,6 +28,14 @@ extern "C"
{
#endif
/* project version */
#define CJSON_VERSION_MAJOR 1
#define CJSON_VERSION_MINOR 2
#define CJSON_VERSION_PATCH 1
/* returns the version of cJSON as a string */
extern const char* cJSON_Version(void);
#include <stddef.h>
/* cJSON Types: */

View File

@@ -208,6 +208,11 @@ cJSON *cJSONUtils_GetPointer(cJSON *object, const char *pointer)
static void cJSONUtils_InplaceDecodePointerString(char *string)
{
char *s2 = string;
if (string == NULL) {
return;
}
for (; *string; s2++, string++)
{
*s2 = (*string != '~')
@@ -229,12 +234,19 @@ static cJSON *cJSONUtils_PatchDetach(cJSON *object, const char *path)
/* copy path and split it in parent and child */
parentptr = cJSONUtils_strdup(path);
childptr = strrchr(parentptr, '/'); /* last '/' */
if (childptr)
{
/* split strings */
*childptr++ = '\0';
if (parentptr == NULL) {
return NULL;
}
childptr = strrchr(parentptr, '/'); /* last '/' */
if (childptr == NULL)
{
free(parentptr);
return NULL;
}
/* split strings */
*childptr++ = '\0';
parent = cJSONUtils_GetPointer(object, parentptr);
cJSONUtils_InplaceDecodePointerString(childptr);

3
test.c
View File

@@ -382,6 +382,9 @@ int main(void)
"</body>\n"
"</html>\n";
/* print the version */
printf("Version: %s\n", cJSON_Version());
/* Process each json textblock by parsing, then rebuilding: */
doit(text1);
doit(text2);