Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,11 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return
}

buffer.content = (const unsigned char*)value;
buffer.length = strlen((const char*)value) + sizeof("");
if(return_parse_end && *return_parse_end){
buffer.length = (size_t)(*return_parse_end - value);
}else{
buffer.length = strlen((const char*)value) + sizeof("");
}
buffer.offset = 0;
buffer.hooks = global_hooks;

Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ if(ENABLE_CJSON_TEST)
set(unity_tests
parse_examples
parse_number
parse_memory
parse_hex4
parse_string
parse_array
Expand Down
26 changes: 26 additions & 0 deletions tests/parse_memory.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "common.h"
#include "unity/examples/unity_config.h"
#include "unity/src/unity.h"

static void parse_memory_should_parse_true(void) {
cJSON *item;
const char *mem =
"{"
"\"hello\":\"world\""
"}",
*end = mem + strlen(mem);
item = cJSON_ParseWithOpts(mem, &end, false);
TEST_ASSERT_NOT_NULL(item);
cJSON_Delete(item);
}

int main(void) {
/* initialize cJSON item */
UNITY_BEGIN();
RUN_TEST(parse_memory_should_parse_true);
return UNITY_END();
}