json_object_set_new

333 views
Skip to first unread message

sthu...@gmail.com

unread,
Sep 2, 2014, 7:22:17 AM9/2/14
to jansso...@googlegroups.com

I am using json_object_set_new() api to set a large string (of approx 2K) to an object using json_string().

n = json_object_set_new(sdp, "addr", json_string(addr_buf));

However, this api is returning -1. How do I debug this and under what conditions does the API return failure?

Thanks.




Petri Lehtinen

unread,
Sep 2, 2014, 8:01:52 AM9/2/14
to jansso...@googlegroups.com
In your case, json_object_set_new() returns -1 if:

- sdp is not an object

- json_string(addr_buf) returns NULL

- memory allocation fails when allocating space for the internal
structures of the hash table

json_string(addr_buf) returs NULL if:

- addr_buf is NULL or not valid UTF-8

- memory allocation fails

Petri

sthustfo

unread,
Sep 2, 2014, 2:01:27 PM9/2/14
to jansso...@googlegroups.com
Indeed json_string() is returning NULL and the cause seems to be invalid UTF-8 (because addr_buf is not NULL). Any pointers on how to validate that it is a proper UTF-8 string? because content seems to be harmless and contains pure ascii text.



--
--
Jansson users mailing list
jansso...@googlegroups.com
http://groups.google.com/group/jansson-users
---
You received this message because you are subscribed to a topic in the Google Groups "Jansson users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jansson-users/nEdzz6bD5n4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jansson-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sthustfo

unread,
Sep 2, 2014, 2:22:55 PM9/2/14
to jansso...@googlegroups.com
I was able to find the issue with the string and fixed it. Thanks for clarifications.
Reply all
Reply to author
Forward
0 new messages