summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/map/atcommand.c12
-rw-r--r--src/map/channel.c3
2 files changed, 7 insertions, 8 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index adf617ccd..f46ce0362 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -9125,14 +9125,12 @@ ACMD(channel)
return false;
}
if (VECTOR_INDEX(sd->channels, k)->type == HCS_TYPE_ALLY) {
- do {
- for (k = 0; k < VECTOR_LENGTH(sd->channels); k++) {
- if (VECTOR_INDEX(sd->channels, k)->type == HCS_TYPE_ALLY) {
- channel->leave(VECTOR_INDEX(sd->channels, k), sd);
- break;
- }
+ for (k = VECTOR_LENGTH(sd->channels) - 1; k >= 0; k--) {
+ // Loop downward to avoid issues when channel->leave() compacts the array
+ if (VECTOR_INDEX(sd->channels, k)->type == HCS_TYPE_ALLY) {
+ channel->leave(VECTOR_INDEX(sd->channels, k), sd);
}
- } while (k != VECTOR_LENGTH(sd->channels)); // FIXME
+ }
} else {
channel->leave(VECTOR_INDEX(sd->channels, k), sd);
}
diff --git a/src/map/channel.c b/src/map/channel.c
index 86ca44ea2..e27e9fb0b 100644
--- a/src/map/channel.c
+++ b/src/map/channel.c
@@ -565,7 +565,8 @@ static void channel_guild_leave_alliance(const struct guild *g_source, const str
static void channel_quit_guild(struct map_session_data *sd)
{
nullpo_retv(sd);
- for (int i = 0; i < VECTOR_LENGTH(sd->channels); i++) { // FIXME
+ for (int i = VECTOR_LENGTH(sd->channels) - 1; i >= 0; i--) {
+ // Loop downward to avoid issues when channel->leave() compacts the array
struct channel_data *chan = VECTOR_INDEX(sd->channels, i);
if (chan->type != HCS_TYPE_ALLY)