]> granicus.if.org Git - json-c/commitdiff
json_object_deep_copy: fix deep copy of strings containing '\0'
authorRamiro Polla <ramiro.polla@gmail.com>
Sat, 1 Dec 2018 23:23:30 +0000 (00:23 +0100)
committerRamiro Polla <ramiro.polla@gmail.com>
Thu, 20 Dec 2018 21:26:06 +0000 (22:26 +0100)
json_object.c
tests/test_deep_copy.c
tests/test_deep_copy.expected

index 1d9a53c1f3d13c0dc1a68e99c93f4cfead30dc9e..e3c5744d906de973ae387b998eac72662830bddb 100644 (file)
@@ -1388,7 +1388,7 @@ int json_c_shallow_copy_default(json_object *src, json_object *parent, const cha
                break;
 
        case json_type_string:
-               *dst = json_object_new_string(get_string_component(src));
+               *dst = json_object_new_string_len(get_string_component(src), src->o.c_string.len);
                break;
 
        case json_type_object:
index 7a6e63f8192b9bd5a51eebd4cef5dc9327bf880d..53b8a84f97ffa950b97a00e5ed75daa29ea4244f 100644 (file)
@@ -18,6 +18,7 @@ static const char *json_str1 =
 "        \"GlossDiv\": {"
 "            \"title\": \"S\","
 "            \"null_obj\": null, "
+"            \"null_str\": \" \\u0000 \","
 "            \"GlossList\": {"
 "                \"GlossEntry\": {"
 "                    \"ID\": \"SGML\","
index d009e948bfc53782cfd631b10538cdd13fc6b0bf..ef65b6448d322da8b1589a678acf160126933562 100644 (file)
@@ -13,6 +13,7 @@ Printing JSON objects for visual inspection
     "GlossDiv":{
       "title":"S",
       "null_obj":null,
+      "null_str":" \u0000 ",
       "GlossList":{
         "GlossEntry":{
           "ID":"SGML",