kbranigan / cjson Goto Github PK
View Code? Open in Web Editor NEWI did not write this code, but I like it.
Home Page: https://github.com/DaveGamble/cJSON
License: MIT License
I did not write this code, but I like it.
Home Page: https://github.com/DaveGamble/cJSON
License: MIT License
In cJSON_Utils.c#L208 logical inconsistencies:
if (!patches->type==cJSON_Array) return 1; /* malformed patches. */
I assume here should be:
if (patches->type!=cJSON_Array) return 1; /* malformed patches. */
hello.
i meet a problem from use cjson.
memory keeps growing.
following code:
void test(){
cJSON * pJsonRoot = NULL;
pJsonRoot = cJSON_CreateObject();
if(NULL == pJsonRoot)
{
return 0;
}
cJSON_AddStringToObject(pJsonRoot, "hello", "hello world");
cJSON_AddNumberToObject(pJsonRoot, "number", 10010);
cJSON_AddBoolToObject(pJsonRoot, "bool", 1);
cJSON * pSubJson = NULL;
pSubJson = cJSON_CreateObject();
if(NULL == pSubJson)
{
cJSON_Delete(pJsonRoot);
return 0;
}
cJSON_AddStringToObject(pSubJson, "subjsonobj", "a sub json string");
cJSON_AddItemToObject(pJsonRoot, "subobj", pSubJson);
char * p = cJSON_Print(pJsonRoot);
if(NULL == p)
{
/*//convert json list to string faild, exit*/
/*//because sub json pSubJson han been add to pJsonRoot, so just delete pJsonRoot, if you also delete pSubJson, it will coredump, and error is : double free*/
cJSON_Delete(pJsonRoot);
return 0;
}
printf("%s\n", p);
printf("%d",strlen(p));
free(p);
}
int main()
{
int i;
for(i=0;i<100;i++){
if(i==1||i==50||i==99){
printf("%d",i);
}
test();
}
}
debug one i=1 memory 344k
two i=50 memory 376k
three i=100 memory 408k
Memory is not released there?
thanks
This is discussed here:
bungle/lua-resty-libcjson#6
That is LuaJIT FFI binding to this library. There is also an example that triggers this problem. I'm pretty sure the leak is in C-module, but it could be in my code as well, but I have not spotted it.
cJSON_CreateNumber does not take care if number is unsigned. It always assume the input value is signed. There is no way to handle this. Maybe different function and different type identifier?
e.g. cJSON_SNumber and cJSON_UNumber something...
Program received signal SIGSEGV, Segmentation fault.
0x0000000000403d12 in cJSON_AddItemToArray ()
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.132.el6_5.2.x86_64
Question:
How can I add the double value only with given precision as provided 100.2 instead of 100.200000. Is it possible to generate the expected result below?
(When I gave the same number as float number = 100.2
;, it generates: {"number value":100.199997} )
Example code:
double number = 100.2;
cJSON_AddNumberToObject(json, "number value", number);
Expected result:
{"number value":100.2}
Generated result:
{"number value":100.200000}
Anybody ever tried to parse a non-json message? For example: {"test":12
^^ Note that there is no ending accolade...
For me this gives a segmentation fault. Would it be better if this would return an empty json object?
Good afternoon.
I am using cJSON v1.7.12. I am trying to create a json of the form:
{ "status":"text", "num": 123 }
For this, I use the following code:
`
cJSON *monitor = cJSON_CreateObject();
if (monitor == NULL)
{
cJSON_Delete(monitor);
ESP_LOGE(TAG, "Error create json");
}
cJSON *status = cJSON_CreateString("text");
if (status == NULL)
{
cJSON_Delete(monitor);
ESP_LOGE(TAG, "Error create status");
}
cJSON_AddItemToObject(monitor, "status", status);
int k = 123;
cJSON *num = cJSON_CreateNumber(k);
ESP_LOGI(TAG, "End cJSON_CreateNumber");
if (num == NULL)
{
cJSON_Delete(monitor);
ESP_LOGE(TAG, "Error create num");
}
cJSON_AddItemToObject(monitor, "num", num);
ESP_LOGI(TAG, "End cJSON_AddItemToObject");
char* resp_str = cJSON_PrintUnformatted(monitor);
ESP_LOGI(TAG, "End cJSON_Print");
ESP_LOGI(TAG, "out_json: \n '%s'", resp_str);
`
I found that if cJSON_CreateNumber is in my code, then the cJSON_Print function returns null. What is the reason for this problem?
This repository is effectively a fork (in the non-GitHub sense) of the original cJSON. None of your changes are being upstreamed to the original maintainer, who seems to still be active in maintaining cJSON. Please choose whether you're a permanent fork or not.
If you decide you're a permanent fork, please kindling rename the project and make it clear in your README that this is a fork from the original.
If you decide that you're going to cooperate with Dave, please upstream all the changes you have here. If you keep accepting further pull requests, which you're allowed to, you will need to work with the upstream maintainer to get the changes in. He may not want some or all of them, in which case you will have to reject the pull request.
@kbranigan I am targeting for angular beta project. I need d.ts file for cjson to import in the angular component. Please help me.
#Thanks
Vijay
Heya,
I've set up a repo here: https://github.com/DaveGamble/cJSON
I'll get on with fixing and updating things :)
Dave.
Please contact me for 246 crash cases found by fuzzing with afl. It's likely there aren't 246 actual errors, just 246 ways to get to the same few. These issues should be treated as critical since JSON parsing is often exposed on the attack surface.
I can't get elements of a JSON arrary, using cJSON_GetArrayItem(),
because rather json_arrary->child->child == first-element-of-JSON-array
than json_arrary->child == first-element-of-JSON-array.
json_arrary->child->|other members| == 0x0;
Why ?
I'm sorry about my english. :-)
I got a notification from sourceforge site that a new version of cJSON is available. I got the tarball and there is a lot of C code differences.
Anyone of you knows what are the changes about ? are those changes merged into this repository ?
note: if you know how to contact Dave Gamble please let me know
While parsing the below json, elements ipv4 and ipv6 are not parsed as CJSON_Array. They are parsed as cJSON_NULL and I am wondering why ? Does "ipv6" : null at one place (marked in bold) throws the parsing off ?
Thanks,
Medha
{
"data": {
"IDN": {
"ipv4": [
{
"accepted-prefix-count": 0,
"active-prefix-count": 0,
"received-prefix-count": 0,
"suppressed-prefix-count": 0,
"peer-as": 65031,
"instances": [
"tb1-vrr01",
"tb1-vrr02"
],
"peer-state": {
"tb1-vrr01": "Active",
"tb1-vrr02": "Active"
},
"peer-address": "169.254.3.1",
"elapsed-time": {
"tb1-vrr01": 3986,
"tb1-vrr02": 4005
},
"vpn": "IDN"
},
{
"accepted-prefix-count": 0,
"active-prefix-count": 0,
"received-prefix-count": 0,
"suppressed-prefix-count": 0,
"peer-as": 65031,
"instances": [
"tb1-vrr01",
"tb1-vrr02"
],
"peer-state": {
"tb1-vrr01": "Connect",
"tb1-vrr02": "Active"
},
"peer-address": "169.254.3.2",
"elapsed-time": {
"tb1-vrr01": 3986,
"tb1-vrr02": 4005
},
"vpn": "IDN"
},
{
"accepted-prefix-count": 0,
"active-prefix-count": 0,
"received-prefix-count": 0,
"suppressed-prefix-count": 0,
"peer-as": 65032,
"instances": [
"tb1-vrr01",
"tb1-vrr02"
],
"peer-state": {
"tb1-vrr01": "Connect",
"tb1-vrr02": "Active"
},
"peer-address": "169.254.3.3",
"elapsed-time": {
"tb1-vrr01": 3988,
"tb1-vrr02": 4006
},
"vpn": "IDN"
},
{
"accepted-prefix-count": 0,
"active-prefix-count": 0,
"received-prefix-count": 0,
"suppressed-prefix-count": 0,
"peer-as": 65032,
"instances": [
"tb1-vrr02",
"tb1-vrr01"
],
"peer-state": {
"tb1-vrr01": "Active",
"tb1-vrr02": "Active"
},
"peer-address": "169.254.3.4",
"elapsed-time": {
"tb1-vrr01": 3988,
"tb1-vrr02": 4007
},
"vpn": "IDN"
},
{
"accepted-prefix-count": 0,
"active-prefix-count": 0,
"received-prefix-count": 0,
"suppressed-prefix-count": 0,
"peer-as": 65033,
"instances": [
"tb1-vrr01",
"tb1-vrr02"
],
"peer-state": {
"tb1-vrr01": "Connect",
"tb1-vrr02": "Active"
},
"peer-address": "169.254.3.5",
"elapsed-time": {
"tb1-vrr01": 3990,
"tb1-vrr02": 4006
},
"vpn": "IDN"
},
{
"accepted-prefix-count": 0,
"active-prefix-count": 0,
"received-prefix-count": 0,
"suppressed-prefix-count": 0,
"peer-as": 65033,
"instances": [
"tb1-vrr01",
"tb1-vrr02"
],
"peer-state": {
"tb1-vrr01": "Connect",
"tb1-vrr02": "Active"
},
"peer-address": "169.254.3.6",
"elapsed-time": {
"tb1-vrr01": 3989,
"tb1-vrr02": 4005
},
"vpn": "IDN"
}
],
"ipv6": null
},
"VCP": {
"ipv4": [
{
"accepted-prefix-count": 0,
"active-prefix-count": 0,
"received-prefix-count": 0,
"suppressed-prefix-count": 0,
"peer-as": 65002,
"instances": [
"tb1-vrr01",
"tb1-vrr02"
],
"peer-state": {
"tb1-vrr01": "Active",
"tb1-vrr02": "Active"
},
"peer-address": "169.254.2.1",
"elapsed-time": {
"tb1-vrr01": 3988,
"tb1-vrr02": 4004
},
"vpn": "VCP"
},
{
"accepted-prefix-count": 0,
"active-prefix-count": 0,
"received-prefix-count": 0,
"suppressed-prefix-count": 0,
"peer-as": 65002,
"instances": [
"tb1-vrr01",
"tb1-vrr02"
],
"peer-state": {
"tb1-vrr01": "Connect",
"tb1-vrr02": "Active"
},
"peer-address": "169.254.2.2",
"elapsed-time": {
"tb1-vrr01": 3984,
"tb1-vrr02": 4007
},
"vpn": "VCP"
},
{
"accepted-prefix-count": 0,
"active-prefix-count": 0,
"received-prefix-count": 0,
"suppressed-prefix-count": 0,
"peer-as": 65002,
"instances": [
"tb1-vrr01",
"tb1-vrr02"
],
"peer-state": {
"tb1-vrr01": "Active",
"tb1-vrr02": "Active"
},
"peer-address": "169.254.2.17",
"elapsed-time": {
"tb1-vrr01": 3993,
"tb1-vrr02": 4005
},
"vpn": "VCP"
},
{
"accepted-prefix-count": 0,
"active-prefix-count": 0,
"received-prefix-count": 0,
"suppressed-prefix-count": 0,
"peer-as": 65002,
"instances": [
"tb1-vrr01",
"tb1-vrr02"
],
"peer-state": {
"tb1-vrr01": "Active",
"tb1-vrr02": "Connect"
},
"peer-address": "169.254.2.18",
"elapsed-time": {
"tb1-vrr01": 3992,
"tb1-vrr02": 4006
},
"vpn": "VCP"
}
],
"ipv6": [
{
"accepted-prefix-count": 0,
"active-prefix-count": 0,
"received-prefix-count": 0,
"suppressed-prefix-count": 0,
"peer-as": 65002,
"instances": [
"tb1-vrr01",
"tb1-vrr02"
],
"peer-state": {
"tb1-vrr01": "Active",
"tb1-vrr02": "Active"
},
"peer-address": "fdf8::2:1",
"elapsed-time": {
"tb1-vrr01": 3994,
"tb1-vrr02": 4005
},
"vpn": "VCP"
},
{
"accepted-prefix-count": 0,
"active-prefix-count": 0,
"received-prefix-count": 0,
"suppressed-prefix-count": 0,
"instances": [
"tb1-vrr01",
"tb1-vrr02"
],
"peer-state": {
"tb1-vrr01": "Connect",
"tb1-vrr02": "Connect"
},
"peer-address": "fdf8::2:2",
"elapsed-time": {
"tb1-vrr01": 3984,
"tb1-vrr02": 4006
},
"vpn": "VCP"
},
{
"accepted-prefix-count": 0,
"active-prefix-count": 0,
"received-prefix-count": 0,
"suppressed-prefix-count": 0,
"peer-as": 65002,
"instances": [
"tb1-vrr01",
"tb1-vrr02"
],
"peer-state": {
"tb1-vrr01": "Active",
"tb1-vrr02": "Active"
},
"peer-address": "fdf8::2:81",
"elapsed-time": {
"tb1-vrr01": 3986,
"tb1-vrr02": 4007
},
"vpn": "VCP"
},
{
"accepted-prefix-count": 0,
"active-prefix-count": 0,
"received-prefix-count": 0,
"suppressed-prefix-count": 0,
"peer-as": 65002,
"instances": [
"tb1-vrr01",
"tb1-vrr02"
],
"peer-state": {
"tb1-vrr01": "Active",
"tb1-vrr02": "Connect"
},
"peer-address": "fdf8::2:82",
"elapsed-time": {
"tb1-vrr01": 3994,
"tb1-vrr02": 4006
},
"vpn": "VCP"
}
]
},
"vpn-names": [
"VCP",
"IDN"
]
},
"data_source": "rest",
"operation": "post_response",
"resource": "bgp_peer_summary",
"system_id": "bgp"
}
The parser parses only 1024 characters!what if my need to parse more.
either -stdc99 or some defines: XOPEN_SOURCE >= 600 || _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L;
Are needed to make compilation work. I'm not sure which is the most desirable. I'm guessing _POSIX_C_SOURCE
I think it will save some space...Ignore this issue if I'm being naive. Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.