commit 17410fed5985559b38f8be4ffe7a550af2cd9b96 from: the xhr date: Thu Sep 16 12:44:34 2021 UTC Also replace some deprecated functions commit - 90922303f0adf011bf662141eb263bf922bfcbc5 commit + 17410fed5985559b38f8be4ffe7a550af2cd9b96 blob - 3f9e0d7ff617a0a991093d4e4748b60b9e002c9f blob + 1a8915419934fe0bd72c5094c0afb373e5850888 --- character.c +++ character.c @@ -476,7 +476,8 @@ save_character() temp_n = json_object_array_length(items); for (i = 0; i < temp_n; i++) { json_object *temp = json_object_array_get_idx(items, i); - json_object *id = json_object_object_get(temp, "id"); + json_object *id; + json_object_object_get_ex(temp, "id", &id); if (curchar->id == json_object_get_int(id)) { log_debug("Update character entry for %s\n", curchar->name); json_object_array_del_idx(items, i, 1); @@ -501,7 +502,7 @@ void delete_saved_character(int id) { char path[_POSIX_PATH_MAX]; - json_object *root; + json_object *root, *lid; int temp_n, i; LIST_INIT(&head); @@ -521,7 +522,7 @@ delete_saved_character(int id) temp_n = json_object_array_length(characters); for (i = 0; i < temp_n; i++) { json_object *temp = json_object_array_get_idx(characters, i); - json_object *lid = json_object_object_get(temp, "id"); + json_object_object_get_ex(temp, "id", &lid); if (id == json_object_get_int(lid)) { json_object_array_del_idx(characters, i, 1); log_debug("Deleted character entry for %d\n", id); @@ -542,6 +543,7 @@ load_characters_list() struct entry *e; char path[_POSIX_PATH_MAX]; json_object *root; + json_object *lid, *name; int temp_n, i; LIST_INIT(&head); @@ -552,12 +554,16 @@ load_characters_list() return; } - json_object *characters = json_object_object_get(root, "characters"); + json_object *characters; + if (!json_object_object_get_ex(root, "characters", &characters)) { + log_debug("Cannot find a [characters] array in %s\n", path); + return; + } temp_n = json_object_array_length(characters); for (i=0; i < temp_n; i++) { json_object *temp = json_object_array_get_idx(characters, i); - json_object *lid = json_object_object_get(temp, "id"); - json_object *name = json_object_object_get(temp, "name"); + json_object_object_get_ex(temp, "id", &lid); + json_object_object_get_ex(temp, "name", &name); log_debug("Add %s to list with id: %d\n", json_object_get_string(name), json_object_get_int(lid)); if ((e = malloc(sizeof(struct entry))) == NULL) @@ -576,7 +582,7 @@ load_character(int id) { struct character *c; char path[_POSIX_PATH_MAX]; - json_object *root; + json_object *root, *lid, *name; int temp_n, i; if (id <= 0) @@ -609,9 +615,9 @@ load_character(int id) temp_n = json_object_array_length(characters); for (i=0; i < temp_n; i++) { json_object *temp = json_object_array_get_idx(characters, i); - json_object *lid = json_object_object_get(temp, "id"); + json_object_object_get_ex(temp, "id", &lid); if (id == json_object_get_int(lid)) { - json_object *name = json_object_object_get(temp, "name"); + json_object_object_get_ex(temp, "name", &name); log_debug("Loading character %s, id: %d\n", json_object_get_string(name), json_object_get_int(lid));