This website works better with JavaScript.
Home
Issues
Pull Requests
Milestones
AI流水线
Repositories
Datasets
论坛
实训
竞赛
大数据
AI开发
Register
Sign In
jdk-build-libs
/
json-c
Not watched
Unwatch
Watch all
Watch but not notify
1
Star
0
Fork
0
Code
Releases
11
Wiki
evaluate
Activity
Issues
0
Pull Requests
0
Datasets
Model
Cloudbrain
HPC
Browse Source
Fix issue
#53
- ensure explicit length string are still NUL terminated, and fix json_tokener_parse() to work properly with embedded unicode \u0000 values in strings.
Adjust test_null to check for this case. See also
http://bugs.debian.org/687269
tags/json-c-0.11-20130402
Eric Haszlakiewicz
13 years ago
parent
7a4506d6df
commit
4e4af93d66
3 changed files
with
23 additions
and
2 deletions
Split View
Diff Options
Show Stats
Download Patch File
Download Diff File
+2
-1
json_object.c
+1
-1
json_tokener.c
+20
-0
tests/test_null.c
+ 2
- 1
json_object.c
View File
@@ -620,8 +620,9 @@ struct json_object* json_object_new_string_len(const char *s, int len)
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;
}
+ 1
- 1
json_tokener.c
View File
@@ -393,7 +393,7 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
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;
+ 20
- 0
tests/test_null.c
View File
@@ -8,6 +8,7 @@
#include "json_inttypes.h"
#include "json_object.h"
#include "json_tokener.h"
int main()
{
@@ -33,5 +34,24 @@ 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;
}
Write
Preview
Loading…
Cancel
Save