Skip to content

Commit 3797eb3

Browse files
committed
bugfix crash vergesse.
1 parent 855d5c8 commit 3797eb3

4 files changed

Lines changed: 33 additions & 2 deletions

File tree

src/economy.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ int forget_cmd(unit * u, order * ord)
286286
ADDMSG(&u->faction->msgs, msg_message("forget", "unit skill", u, sk));
287287
set_level(u, sk, 0);
288288
}
289+
else {
290+
cmistake(u, ord, 77, MSG_EVENT);
291+
}
289292
return 0;
290293
}
291294

src/economy.test.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,19 @@ static void test_forget_cmd(CuTest *tc) {
879879
test_teardown();
880880
}
881881

882+
static void test_forget_cmd_unknown_skill(CuTest *tc) {
883+
unit *u;
884+
885+
test_setup();
886+
u = test_create_unit(test_create_faction(), test_create_plain(0, 0));
887+
test_set_skill(u, SK_CATAPULT, 3, 4);
888+
u->thisorder = create_order(K_FORGET, u->faction->locale, "hurrdurr");
889+
forget_cmd(u, u->thisorder);
890+
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error77"));
891+
CuAssertPtrNotNull(tc, u->skills);
892+
test_teardown();
893+
}
894+
882895
static void test_buy_cmd(CuTest *tc) {
883896
region * r;
884897
unit *u;
@@ -1772,6 +1785,7 @@ CuSuite *get_economy_suite(void)
17721785
SUITE_ADD_TEST(suite, test_tax_cmd);
17731786
SUITE_ADD_TEST(suite, test_trade_is_long_action);
17741787
SUITE_ADD_TEST(suite, test_forget_cmd);
1788+
SUITE_ADD_TEST(suite, test_forget_cmd_unknown_skill);
17751789
SUITE_ADD_TEST(suite, test_buy_cmd);
17761790
SUITE_ADD_TEST(suite, test_buy_twice);
17771791
SUITE_ADD_TEST(suite, test_buy_prices);

src/kernel/order.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static int create_data(keyword_t kwd, const char *s,
266266
if (kwd == K_STUDY || kwd == K_AUTOSTUDY || kwd == K_FORGET) {
267267
const char * sptr = s;
268268
skill_t sk = findskill(parse_token_depr(&sptr), lang);
269-
if (kwd == K_FORGET || (sk != SK_MAGIC && sk != NOSKILL)) {
269+
if (sk != SK_MAGIC && sk != NOSKILL) {
270270
return ((int)sk)-100;
271271
}
272272
}
@@ -597,7 +597,7 @@ keyword_t init_order(const struct order *ord, const struct locale *lang)
597597
assert(sk < MAXSKILLS);
598598
assert(lang);
599599
str = skillname(sk, lang);
600-
if (strchr(str, ' ') == NULL) {
600+
if (!str || strchr(str, ' ') == NULL) {
601601
init_tokens_str(str);
602602
}
603603
else {

src/kernel/order.test.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "eressea.h"
44

55
#include "skill.h"
6+
#include "faction.h"
67
#include "unit.h"
78

89
#include <util/keyword.h> // for keyword, K_STUDY, K_MOVE, init_keywords
@@ -547,6 +548,18 @@ static void test_study_order_quoted(CuTest *tc) {
547548
test_teardown();
548549
}
549550

551+
static void test_forget_order_bad_skill(CuTest *tc) {
552+
test_setup();
553+
unit *u;
554+
u = test_create_unit(test_create_faction(), test_create_plain(0, 0));
555+
556+
u->thisorder = create_order(K_FORGET, u->faction->locale, "hurrdurr");
557+
CuAssertIntEquals(tc, K_FORGET, init_order(u->thisorder, u->faction->locale));
558+
CuAssertStrEquals(tc, "hurrdurr", getstrtoken());
559+
560+
test_teardown();
561+
}
562+
550563
static void test_study_order_unknown_tilde(CuTest *tc) {
551564
char token[32];
552565
stream out;
@@ -666,6 +679,7 @@ CuSuite *get_order_suite(void)
666679
SUITE_ADD_TEST(suite, test_study_order_unknown_tilde);
667680
SUITE_ADD_TEST(suite, test_study_order_unknown_quoted);
668681
SUITE_ADD_TEST(suite, test_study_order_quoted);
682+
SUITE_ADD_TEST(suite, test_forget_order_bad_skill);
669683
SUITE_ADD_TEST(suite, test_parse_order);
670684
SUITE_ADD_TEST(suite, test_parse_parameters);
671685
SUITE_ADD_TEST(suite, test_parse_make);

0 commit comments

Comments
 (0)