diff --git a/src/map/atcommand.c b/src/map/atcommand.c index b6d40b8875e..7078ecdd7c6 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -892,7 +892,11 @@ ACMD(storage) } sd->storage.access = STORAGE_ACCESS_ALL; // Default storage access for atcommands. - stor = storage->ensure(sd, storage_id); + + if ((stor = storage->ensure(sd, storage_id)) == NULL) { + ShowError("atcommand_storage: Error ensuring storage for player %d, storage_id %d\n", sd->bl.id, storage_id); + return false; + } if (stor->received == false) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 27), storage_name); @@ -5526,7 +5530,11 @@ ACMD(storeall) } sd->storage.access = STORAGE_ACCESS_ALL; // Default storage access for atcommands. - stor = storage->ensure(sd, storage_id); + + if ((stor = storage->ensure(sd, storage_id)) == NULL) { + ShowError("atcommand_storeall: Error ensuring storage for player %d, storage_id %d\n", sd->bl.id, storage_id); + return false; + } if (sd->state.storage_flag != STORAGE_FLAG_NORMAL) { //Open storage. @@ -5588,7 +5596,11 @@ ACMD(clearstorage) } sd->storage.access = STORAGE_ACCESS_ALL; // Default storage access for atcommands. - stor = storage->ensure(sd, storage_id); + + if ((stor = storage->ensure(sd, storage_id)) == NULL) { + ShowError("atcommand_clearstorage: Error ensuring storage for player %d, storage_id %d\n", sd->bl.id, storage_id); + return false; + } if (stor->received == false) { clif->message(fd, msg_fd(fd, 27)); // "Storage has not been loaded yet" diff --git a/src/map/clif.c b/src/map/clif.c index cc6abeee988..28f33d5656e 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -9293,7 +9293,9 @@ static void clif_refresh_storagewindow(struct map_session_data *sd) if (stst == NULL) return; - stor = storage->ensure(sd, sd->storage.current); + if ((stor = storage->ensure(sd, sd->storage.current)) == NULL) { + return; + } if (stor->aggregate > 0) { storage->sortitem(VECTOR_DATA(stor->item), VECTOR_LENGTH(stor->item)); @@ -13554,7 +13556,8 @@ static void clif_parse_MoveToKafra(int fd, struct map_session_data *sd) if (sd->state.storage_flag == STORAGE_FLAG_NORMAL) { struct storage_data *stor = storage->ensure(sd, sd->storage.current); - storage->add(sd, stor, item_index, item_amount); + if (stor != NULL) + storage->add(sd, stor, item_index, item_amount); } else if (sd->state.storage_flag == STORAGE_FLAG_GUILD) { gstorage->add(sd, item_index, item_amount); } @@ -13578,7 +13581,8 @@ static void clif_parse_MoveFromKafra(int fd, struct map_session_data *sd) if (sd->state.storage_flag == STORAGE_FLAG_NORMAL) { struct storage_data *stor = storage->ensure(sd, sd->storage.current); - storage->get(sd, stor, item_index, item_amount); + if (stor != NULL) + storage->get(sd, stor, item_index, item_amount); } else if(sd->state.storage_flag == STORAGE_FLAG_GUILD) { gstorage->get(sd, item_index, item_amount); } @@ -13596,7 +13600,8 @@ static void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd) if (sd->state.storage_flag == STORAGE_FLAG_NORMAL) { struct storage_data *stor = storage->ensure(sd, sd->storage.current); - storage->addfromcart(sd, stor, RFIFOW(fd,2) - 2, RFIFOL(fd,4)); + if (stor != NULL) + storage->addfromcart(sd, stor, RFIFOW(fd, 2) - 2, RFIFOL(fd, 4)); } else if (sd->state.storage_flag == STORAGE_FLAG_GUILD) { gstorage->addfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4)); } @@ -13614,7 +13619,8 @@ static void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd) if (sd->state.storage_flag == STORAGE_FLAG_NORMAL) { struct storage_data *stor = storage->ensure(sd, sd->storage.current); - storage->gettocart(sd, stor, RFIFOW(fd,2)-1, RFIFOL(fd,4)); + if (stor != NULL) + storage->gettocart(sd, stor, RFIFOW(fd,2) - 1, RFIFOL(fd, 4)); } else if (sd->state.storage_flag == STORAGE_FLAG_GUILD) { gstorage->gettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4)); } diff --git a/src/map/intif.c b/src/map/intif.c index 31683beb4ee..0bb02107897 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -340,7 +340,8 @@ static void intif_parse_account_storage(int fd) return; } - stor = storage->ensure(sd, RFIFOW(fd, 8)); + if ((stor = storage->ensure(sd, RFIFOW(fd, 8))) == NULL) + return; if (stor->received == true) { ShowError("intif_parse_account_storage: Multiple calls from the inter-server received.\n"); @@ -376,7 +377,8 @@ static void intif_send_account_storage(struct map_session_data *sd, int storage_ nullpo_retv(sd); - stor = storage->ensure(sd, storage_id); + if ((stor = storage->ensure(sd, storage_id)) == NULL) + return; // Assert that at this point in the code, both flags are true. Assert_retv(stor->save == true); @@ -431,7 +433,8 @@ static void intif_parse_account_storage_save_ack(int fd) return; } - stor = storage->ensure(sd, storage_id); + if ((stor = storage->ensure(sd, storage_id)) == NULL) + return; stor->save = false; // Storage has been saved. } diff --git a/src/map/script.c b/src/map/script.c index 5f4ceda30fa..198af8dd53f 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -10989,16 +10989,19 @@ static BUILDIN(openstorage) struct storage_data *stor = NULL; const struct storage_settings *stst = NULL; - if (sd == NULL) + nullpo_retr(false, sd); + + if ((stor = storage->ensure(sd, storage_id)) == NULL) { + script_pushint(st, 0); + ShowError("buildin_openstorage: Error ensuring storage for player aid %d, storage id %d.\n", sd->bl.id, storage_id); return false; + } if ((stst = storage->get_settings(storage_id)) == NULL) { script_pushint(st, 0); ShowWarning("buildin_openstorage: Storage with ID %d was not found!\n", storage_id); return false; } - - stor = storage->ensure(sd, storage_id); if (stor->received == false) { script_pushint(st, 0); diff --git a/src/map/storage.c b/src/map/storage.c index 8f63b0501dc..7bda7ab9a73 100644 --- a/src/map/storage.c +++ b/src/map/storage.c @@ -167,12 +167,12 @@ const struct storage_settings *storage_get_settings(int storage_id) *------------------------------------------*/ static int storage_storageopen(struct map_session_data *sd, struct storage_data *stor) { - const struct storage_settings *stst = storage->get_settings(stor->uid); + const struct storage_settings *stst = NULL; nullpo_ret(sd); - nullpo_ret(stst); - + nullpo_ret(stor); Assert_ret(stor->received == true); // Assert the availability of data. + nullpo_ret(stst = storage->get_settings(stor->uid)); if (sd->state.storage_flag != STORAGE_FLAG_CLOSED) return 1; // Storage is already open. @@ -228,14 +228,16 @@ static int storage_additem(struct map_session_data* sd, struct storage_data *sto { struct item_data *data = NULL; struct item *it = NULL; - const struct storage_settings *stst = storage->get_settings(stor->uid); + const struct storage_settings *stst = NULL; int i; nullpo_retr(1, sd); - nullpo_retr(1, stst); // Assert existence of storage configuration. + nullpo_retr(1, stor); Assert_retr(1, stor->received == true); // Assert the availability of the storage. + Assert_ret(stst = storage->get_settings(stor->uid)); // Assert existence of storage configuration. nullpo_retr(1, item_data); // Assert availability of item data. Assert_retr(1, item_data->nameid > 0); // Assert existence of item in the database. + Assert_retr(1, amount > 0); // Assert quantity of item. data = itemdb->search(item_data->nameid); @@ -308,12 +310,13 @@ static int storage_additem(struct map_session_data* sd, struct storage_data *sto *------------------------------------------*/ static int storage_delitem(struct map_session_data* sd, struct storage_data *stor, int n, int amount) { - const struct storage_settings *stst = storage->get_settings(stor->uid); struct item *it = NULL; + const struct storage_settings *stst = NULL; nullpo_retr(1, sd); - Assert_retr(1, stst); + nullpo_retr(1, stor); Assert_retr(1, stor->received == true); + nullpo_retr(1, stst = storage->get_settings(stor->uid)); Assert_retr(1, n >= 0 && n < VECTOR_LENGTH(stor->item)); it = &VECTOR_INDEX(stor->item, n); @@ -345,13 +348,12 @@ static int storage_delitem(struct map_session_data* sd, struct storage_data *sto *------------------------------------------*/ static int storage_add_from_inventory(struct map_session_data* sd, struct storage_data *stor, int index, int amount) { - const struct storage_settings *stst = storage->get_settings(stor->uid); + const struct storage_settings *stst = NULL; nullpo_ret(sd); - nullpo_ret(stst); nullpo_ret(stor); - Assert_ret(stor->received == true); + nullpo_ret(stst = storage->get_settings(stor->uid)); if ((sd->storage.access & STORAGE_ACCESS_PUT) == 0) { clif->delitem(sd, index, amount, DELITEM_NORMAL); @@ -427,13 +429,12 @@ static int storage_add_to_inventory(struct map_session_data* sd, struct storage_ *------------------------------------------*/ static int storage_storageaddfromcart(struct map_session_data* sd, struct storage_data *stor, int index, int amount) { - const struct storage_settings *stst = storage->get_settings(stor->uid); + const struct storage_settings *stst = NULL; nullpo_ret(sd); - nullpo_ret(stst); nullpo_ret(stor); - Assert_ret(stor->received == true); + nullpo_ret(stst = storage->get_settings(stor->uid)); if ((sd->storage.access & STORAGE_ACCESS_PUT) == 0) { @@ -473,7 +474,7 @@ static int storage_storagegettocart(struct map_session_data* sd, struct storage_ struct item *it = NULL; nullpo_ret(sd); - + nullpo_ret(stor); Assert_ret(stor->received == true); if ((sd->storage.access & STORAGE_ACCESS_GET) == 0) @@ -513,7 +514,8 @@ static void storage_storageclose(struct map_session_data *sd) nullpo_retv(sd); - curr_stor = storage->ensure(sd, sd->storage.current); + if ((curr_stor = storage->ensure(sd, sd->storage.current)) == NULL) + return; clif->storageclose(sd);