user537670
user537670

Reputation: 821

Maximum size of a string parsed using JSON-C

I am new to JSON-C and I need to know whether there is any size limit on the string that can be parsed using json_tokener_parse.

So basically i need to know when i use json_object * jobj = json_tokener_parse(string), is there any size limit on the string that can be passed.

Thanks in advance.

while (ret==0)
    {
      if((ret = dbcp->c_get(dbcp, &keyd, &datad, DB_NEXT))==0){

      if(vflag) {
    printf("broadcast_mode: after dbcp->c_get(dbcp, &keyd, &datad, DB_NEXT)\n");
      }

      my = (myrecord *) datad.data;

      if(vflag) {
    printf("broadcast_mode: after my = (myrecord *) datad.data\n");
      }

      if(vflag) {
        printf("db: %d: key retrieved: data was %s, %d\n", *(int *)keyd.data,my->src, datad.size);
      }
     }
    }
  if(vflag) {
    printf("broadcast_mode: dbp->c_get 2\n");
  }


  if ((ret = dbcp->c_get(dbcp, &keyd, &datad, DB_NEXT)) !=0)
    {
      if(vflag) {
    dbp->err(dbp, ret, "DBcursor->get");
      }
      //goto err;
    }

  if(vflag) {
    printf("broadcast_mode: dbp->c_close\n");
  }

  if ((ret = dbcp->c_close(dbcp)) != 0)
    {
      dbp->err(dbp, ret, "DBcursor->close");
      //return (1);
    }
 ret = dbp->close(dbp, 0);

  if(vflag) {
    printf("broadcast_mode: json_tokener_parse(my->src)\n");
    printf("broadcast_mode: address is %x,%d\n",(unsigned int)my->src,datad.size);
  }


  json_object * jobj = json_tokener_parse(my->src);   

                        here when datad.size is 1024 i get segmentation fault and it works when size is 500

Upvotes: 1

Views: 1436

Answers (1)

ThiefMaster
ThiefMaster

Reputation: 318568

json-c does not use any fixed-size buffers so it's only limited by the amount of memory your application can use.

This is actually what you can expect from a properly written library - using fixed buffers would require them to be huge to avoid problems with long-but-not-extremely-long JSON strings and then there would most likely still be some cases where they were too small. Not to forget all other cases where they'd waste tons of memory.

Upvotes: 5

Related Questions