diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2014-03-30 23:14:12 -0700 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2014-03-31 10:18:49 -0700 |
commit | 1a651243bb2c8e18baa9aac30ac52a62185074e7 (patch) | |
tree | dd2c0bfc448faef129fb64edec9f64d2ab12bfe5 /src/char | |
parent | 769e8ac9c17779a15492d7fcfc1931c014670c2d (diff) | |
download | tmwa-1a651243bb2c8e18baa9aac30ac52a62185074e7.tar.gz tmwa-1a651243bb2c8e18baa9aac30ac52a62185074e7.tar.bz2 tmwa-1a651243bb2c8e18baa9aac30ac52a62185074e7.tar.xz tmwa-1a651243bb2c8e18baa9aac30ac52a62185074e7.zip |
Be stricter about most arrays
Diffstat (limited to 'src/char')
-rw-r--r-- | src/char/char.cpp | 44 | ||||
-rw-r--r-- | src/char/char.hpp | 4 | ||||
-rw-r--r-- | src/char/int_party.cpp | 1 | ||||
-rw-r--r-- | src/char/int_storage.cpp | 4 | ||||
-rw-r--r-- | src/char/inter.cpp | 6 |
5 files changed, 34 insertions, 25 deletions
diff --git a/src/char/char.cpp b/src/char/char.cpp index b74df46..91ff2e2 100644 --- a/src/char/char.cpp +++ b/src/char/char.cpp @@ -46,11 +46,11 @@ #include "../poison.hpp" static -struct mmo_map_server server[MAX_MAP_SERVERS]; +Array<struct mmo_map_server, MAX_MAP_SERVERS> server; static -Session *server_session[MAX_MAP_SERVERS]; +Array<Session *, MAX_MAP_SERVERS> server_session; static -int server_freezeflag[MAX_MAP_SERVERS]; // Map-server anti-freeze system. Counter. 5 ok, 4...0 freezed +Array<int, MAX_MAP_SERVERS> server_freezeflag; // Map-server anti-freeze system. Counter. 5 ok, 4...0 freezed static int anti_freeze_enable = 0; static @@ -313,6 +313,7 @@ AString mmo_char_tostr(struct CharPair *cp) } str_p += '\t'; + assert (p->global_reg_num < GLOBAL_REG_NUM); for (int i = 0; i < p->global_reg_num; i++) if (p->global_reg[i].str) str_p += STRPRINTF("%s,%d ", @@ -411,14 +412,14 @@ bool extract(XString str, CharPair *cp) if (inventory.size() > MAX_INVENTORY) return false; - std::copy(inventory.begin(), inventory.end(), p->inventory); + std::copy(inventory.begin(), inventory.end(), p->inventory.begin()); // number of inventory items is not saved - it just detects nameid 0 // cart was here - no longer supported for (struct skill_loader& sk : skills) { - if (sk.id > MAX_SKILL) + if (sk.id >= MAX_SKILL) return false; p->skill[sk.id].lv = sk.level; p->skill[sk.id].flags = sk.flags; @@ -426,7 +427,7 @@ bool extract(XString str, CharPair *cp) if (vars.size() > GLOBAL_REG_NUM) return false; - std::copy(vars.begin(), vars.end(), p->global_reg); + std::copy(vars.begin(), vars.end(), p->global_reg.begin()); p->global_reg_num = vars.size(); return true; @@ -964,8 +965,10 @@ int mmo_char_send006b(Session *s, struct char_session_data *sd) } static -int set_account_reg2(int acc, int num, struct global_reg *reg) +int set_account_reg2(int acc, Slice<global_reg> reg) { + size_t num = reg.size(); + assert (num < ACCOUNT_REG2_NUM); int c = 0; for (CharPair& cd : char_keys) { @@ -1309,7 +1312,7 @@ void parse_tologin(Session *ls) if (RFIFOREST(ls) < 4 || RFIFOREST(ls) < RFIFOW(ls, 2)) return; { - struct global_reg reg[ACCOUNT_REG2_NUM]; + Array<struct global_reg, ACCOUNT_REG2_NUM> reg; int j, p, acc; acc = RFIFOL(ls, 4); for (p = 8, j = 0; @@ -1319,7 +1322,7 @@ void parse_tologin(Session *ls) reg[j].str = stringish<VarName>(RFIFO_STRING<32>(ls, p)); reg[j].value = RFIFOL(ls, p + 32); } - set_account_reg2(acc, j, reg); + set_account_reg2(acc, Slice<struct global_reg>(reg.begin(), j)); size_t len = RFIFOW(ls, 2); uint8_t buf[len]; @@ -1980,7 +1983,7 @@ void parse_frommap(Session *ms) if (RFIFOREST(ms) < 4 || RFIFOREST(ms) < RFIFOW(ms, 2)) return; { - struct global_reg reg[ACCOUNT_REG2_NUM]; + Array<struct global_reg, ACCOUNT_REG2_NUM> reg; int p, j; int acc = RFIFOL(ms, 4); for (p = 8, j = 0; @@ -1990,7 +1993,7 @@ void parse_frommap(Session *ms) reg[j].str = stringish<VarName>(RFIFO_STRING<32>(ms, p)); reg[j].value = RFIFOL(ms, p + 32); } - set_account_reg2(acc, j, reg); + set_account_reg2(acc, Slice<struct global_reg>(reg.begin(), j)); // loginサーバーへ送る if (login_session) { @@ -2831,34 +2834,37 @@ bool char_confs(XString key, ZString value) return sum; } -int do_init(int argc, ZString *argv) +int do_init(Slice<ZString> argv) { + ZString argv0 = argv.pop_front(); + bool loaded_config_yet = false; - for (int i = 1; i < argc; ++i) + while (argv) { - if (argv[i].startswith('-')) + ZString argvi = argv.pop_front(); + if (argvi.startswith('-')) { - if (argv[i] == "--help") + if (argvi == "--help") { PRINTF("Usage: %s [--help] [--version] [files...]\n", - argv[0]); + argv0); exit(0); } - else if (argv[i] == "--version") + else if (argvi == "--version") { PRINTF("%s\n", CURRENT_VERSION_STRING); exit(0); } else { - FPRINTF(stderr, "Unknown argument: %s\n", argv[i]); + FPRINTF(stderr, "Unknown argument: %s\n", argvi); runflag = false; } } else { loaded_config_yet = true; - runflag &= load_config_file(argv[i], char_confs); + runflag &= load_config_file(argvi, char_confs); } } diff --git a/src/char/char.hpp b/src/char/char.hpp index 377b1c6..f765b39 100644 --- a/src/char/char.hpp +++ b/src/char/char.hpp @@ -3,8 +3,6 @@ # include "../strings/fwd.hpp" -# include "../generic/const_array.hpp" - # include "../mmo/ip.hpp" # include "../mmo/mmo.hpp" @@ -17,7 +15,7 @@ struct mmo_map_server IP4Address ip; short port; int users; - MapName maps[MAX_MAP_PER_SERVER]; + Array<MapName, MAX_MAP_PER_SERVER> maps; }; const CharPair *search_character(CharName character_name); diff --git a/src/char/int_party.cpp b/src/char/int_party.cpp index c0bedde..864972d 100644 --- a/src/char/int_party.cpp +++ b/src/char/int_party.cpp @@ -381,6 +381,7 @@ void mapif_party_leaved(int party_id, int account_id, CharName name) static void mapif_party_membermoved(struct party *p, int idx) { + assert (idx < MAX_PARTY); unsigned char buf[29]; WBUFW(buf, 0) = 0x3825; diff --git a/src/char/int_storage.cpp b/src/char/int_storage.cpp index 0794c8f..d2782b4 100644 --- a/src/char/int_storage.cpp +++ b/src/char/int_storage.cpp @@ -83,8 +83,10 @@ bool extract(XString str, struct storage *p) if (storage_items.size() > MAX_STORAGE) return false; - std::copy(storage_items.begin(), storage_items.end(), p->storage_); + std::copy(storage_items.begin(), storage_items.end(), p->storage_.begin()); + if (p->storage_amount != storage_items.size()) + PRINTF("WARNING: storage desync for %d\n", p->account_id); return true; } diff --git a/src/char/inter.cpp b/src/char/inter.cpp index c287844..0c41c86 100644 --- a/src/char/inter.cpp +++ b/src/char/inter.cpp @@ -35,7 +35,7 @@ AString accreg_txt = "save/accreg.txt"; struct accreg { int account_id, reg_num; - struct global_reg reg[ACCOUNT_REG_NUM]; + Array<struct global_reg, ACCOUNT_REG_NUM> reg; }; static Map<int, struct accreg> accreg_db; @@ -63,6 +63,7 @@ int inter_recv_packet_length[] = static AString inter_accreg_tostr(struct accreg *reg) { + assert(reg->reg_num < ACCOUNT_REG_NUM); MString str; str += STRPRINTF("%d\t", reg->account_id); for (int j = 0; j < reg->reg_num; j++) @@ -85,7 +86,7 @@ bool extract(XString str, struct accreg *reg) if (vars.size() > ACCOUNT_REG_NUM) return false; - std::copy(vars.begin(), vars.end(), reg->reg); + std::copy(vars.begin(), vars.end(), reg->reg.begin()); reg->reg_num = vars.size(); return true; } @@ -263,6 +264,7 @@ void mapif_account_reg_reply(Session *s, int account_id) } else { + assert (reg->reg_num < ACCOUNT_REG_NUM); int j, p; for (j = 0, p = 8; j < reg->reg_num; j++, p += 36) { |