Code Monkey home page Code Monkey logo

cjson's People

Contributors

alvarez86 avatar anton-sergeev avatar blattms avatar davegamble avatar dongwenhuang avatar etodd avatar ffontaine avatar fsmaxb avatar irwand avatar jfether avatar kbranigan avatar npi3pak avatar rdleal avatar rmeertens avatar rvagg avatar schmidtw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cjson's Issues

Compilation warning

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. */

memory problem

hello.

i meet a problem from use cjson.
memory keeps growing.

following code:

include <stdio.h>

include "cJSON.h"

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

Possible memory leak

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 with unsigned number

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...

Precision problem of cJSON_AddNumberToObject(); with double and float.

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}

Segmentation fault when parsing non-json message

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?

cJSON_Print return NULL

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?

Changes are not being upstreamed to original cJSON

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.

Crashes found with afl

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 get a error when read elements of a JSON arrary

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. :-)

cJSON new version ?

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

My JSON doesn't get parsed correctly

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"
}

New fpclassify code fails to compile on Linux

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.