forked from github/server
fix memory access in rc_setoption
This commit is contained in:
parent
923f01190c
commit
8a638859fd
|
@ -217,7 +217,7 @@ static unit *setup_trade_unit(CuTest *tc, region *r, const struct race *rc) {
|
|||
}
|
||||
|
||||
static void test_trade_insect(CuTest *tc) {
|
||||
/* Insekten können in Wüsten und Sümpfen auch ohne Burgen handeln. */
|
||||
/* Insekten k<EFBFBD>nnen in W<>sten und S<>mpfen auch ohne Burgen handeln. */
|
||||
unit *u;
|
||||
region *r;
|
||||
const item_type *it_luxury;
|
||||
|
@ -239,6 +239,8 @@ static void test_trade_insect(CuTest *tc) {
|
|||
LOC(u->faction->locale, resourcename(it_luxury->rtype, 0))));
|
||||
|
||||
set_item(u, it_silver, 10);
|
||||
CuAssertPtrEquals(tc, r, u->region);
|
||||
CuAssertPtrEquals(tc, (void *)it_luxury, (void *)r_luxury(u->region));
|
||||
produce(u->region);
|
||||
CuAssertIntEquals(tc, 1, get_item(u, it_luxury));
|
||||
CuAssertIntEquals(tc, 5, get_item(u, it_silver));
|
||||
|
|
|
@ -106,18 +106,19 @@ static void rc_setoption(race *rc, int k, const char *value) {
|
|||
rc->options->key[1] = RCO_NONE;
|
||||
v = rc->options->value;
|
||||
} else {
|
||||
for (i=0;!v && i < MAXOPTIONS && rc->options->key[i]!=RCO_NONE;++i) {
|
||||
for (i=0;!v && i < MAXOPTIONS;++i) {
|
||||
if (rc->options->key[i]==key) {
|
||||
v = rc->options->value+i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!v) {
|
||||
assert(i<MAXOPTIONS || !"MAXOPTIONS too small for race");
|
||||
if (rc->options->key[i]==RCO_NONE) {
|
||||
v = rc->options->value+i;
|
||||
rc->options->key[i] = key;
|
||||
if (i+1<MAXOPTIONS) {
|
||||
if (i+1 < MAXOPTIONS) {
|
||||
rc->options->key[i+1]=RCO_NONE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
assert(v);
|
||||
|
|
Loading…
Reference in New Issue