mirror of
https://github.com/json-c/json-c.git
synced 2026-03-27 00:49:07 +08:00
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.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user