diff options
author | Alexander Klauer <Alexander.Klauer@itwm.fraunhofer.de> | 2013-01-08 14:24:21 +0100 |
---|---|---|
committer | Alexander Klauer <Alexander.Klauer@itwm.fraunhofer.de> | 2013-01-08 14:24:21 +0100 |
commit | 2be921d88376e78f84d79aafa6db2714da804e59 (patch) | |
tree | 1ac0e1fc7f4a3a8a8d3109830e840782465fcd2a /json_object.c | |
parent | 85da28c53420659620bad73943436bb5115c2a4a (diff) | |
download | json-c-2be921d88376e78f84d79aafa6db2714da804e59.tar.gz |
Fixed json_object_object_add().
* Return value of json_object_object_add() changed from void to int.
Return value now indicates success or failure.
* Check whether allocations are successful.
* Do not exit program from within the library.
Diffstat (limited to 'json_object.c')
-rw-r--r-- | json_object.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/json_object.c b/json_object.c index 6060554..39c9327 100644 --- a/json_object.c +++ b/json_object.c @@ -371,7 +371,7 @@ struct lh_table* json_object_get_object(struct json_object *jso) } } -void json_object_object_add(struct json_object* jso, const char *key, +int json_object_object_add(struct json_object* jso, const char *key, struct json_object *val) { // We lookup the entry and replace the value, rather than just deleting @@ -381,13 +381,19 @@ void json_object_object_add(struct json_object* jso, const char *key, existing_entry = lh_table_lookup_entry(jso->o.c_object, (void*)key); if (!existing_entry) { - lh_table_insert(jso->o.c_object, strdup(key), val); - return; + char * keydup = strdup( key ); + if ( keydup == NULL ) { + return -1; + } + + return lh_table_insert(jso->o.c_object, keydup, val); } existing_value = (void *)existing_entry->v; if (existing_value) json_object_put(existing_value); existing_entry->v = val; + + return 0; } struct json_object* json_object_object_get(struct json_object* jso, const char *key) |