Adjust test_null to check for this case.
See also http://bugs.debian.org/687269
if(!jso) return NULL;
jso->_delete = &json_object_string_delete;
jso->_to_json_string = &json_object_string_to_json_string;
- jso->o.c_string.str = (char*)malloc(len);
+ jso->o.c_string.str = (char*)malloc(len + 1);
memcpy(jso->o.c_string.str, (void *)s, len);
+ jso->o.c_string.str[len] = '\0';
jso->o.c_string.len = len;
return jso;
}
while(1) {
if(c == tok->quote_char) {
printbuf_memappend_fast(tok->pb, case_start, str-case_start);
- current = json_object_new_string(tok->pb->buf);
+ current = json_object_new_string_len(tok->pb->buf, tok->pb->bpos);
saved_state = json_tokener_state_finish;
state = json_tokener_state_eatws;
break;
#include "json_inttypes.h"
#include "json_object.h"
+#include "json_tokener.h"
int main()
{
retval=1;
}
json_object_put(string);
+
+ struct json_object *parsed_str = json_tokener_parse(expected);
+ if (parsed_str)
+ {
+ int parsed_len = json_object_get_string_len(parsed_str);
+ const char *parsed_cstr = json_object_get_string(parsed_str);
+ int ii;
+ printf("Re-parsed object string len=%d, chars=[", parsed_len);
+ for (ii = 0; ii < parsed_len ; ii++)
+ {
+ printf("%s%d", (ii ? ", " : ""), (int)parsed_cstr[ii]);
+ }
+ printf("]\n");
+ json_object_put(parsed_str);
+ }
+ else
+ {
+ printf("ERROR: failed to parse\n");
+ }
return retval;
}