From fdd28835b5b0fa15e6c09f4a0eecda5ce3fbd7c8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Nov 2017 07:51:31 +0100 Subject: [PATCH] Shifting signed 32-bit value by 31 bits is undefined behaviour --- src/kernel/build.test.c | 2 +- src/kernel/item.c | 6 +++--- src/kernel/pool.c | 4 ++-- src/kernel/race.h | 8 ++++---- src/kernel/xmlreader.c | 8 ++++---- src/modules/autoseed.c | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/kernel/build.test.c b/src/kernel/build.test.c index 8cd408b09..f0970ec06 100644 --- a/src/kernel/build.test.c +++ b/src/kernel/build.test.c @@ -207,7 +207,7 @@ static void test_build_building_with_golem(CuTest *tc) { const building_type *btype; u = setup_build(&bf); - bf.rc->flags |= RCF_STONEGOLEM; + bf.rc->ec_flags |= ECF_STONEGOLEM; btype = bt_find("castle"); assert(btype); assert(btype->construction); diff --git a/src/kernel/item.c b/src/kernel/item.c index 89c532297..fdc9b45d1 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -105,10 +105,10 @@ static int res_changepeasants(unit * u, const resource_type * rtype, int delta) } static int golem_factor(const unit *u, const resource_type *rtype) { - if (rtype == get_resourcetype(R_STONE) && (u_race(u)->flags & RCF_STONEGOLEM)) { + if (rtype == get_resourcetype(R_STONE) && (u_race(u)->ec_flags & ECF_STONEGOLEM)) { return GOLEM_STONE; } - if (rtype == get_resourcetype(R_IRON) && (u_race(u)->flags & RCF_IRONGOLEM)) { + if (rtype == get_resourcetype(R_IRON) && (u_race(u)->ec_flags & ECF_IRONGOLEM)) { return GOLEM_IRON; } return 0; @@ -665,7 +665,7 @@ static int mod_dwarves_only(const unit * u, const region * r, skill_t sk, int value) { UNUSED_ARG(r); - if (u_race(u) == get_race(RC_DWARF) || (u_race(u)->flags & RCF_IRONGOLEM)) { + if (u_race(u) == get_race(RC_DWARF) || (u_race(u)->ec_flags & ECF_IRONGOLEM)) { return value; } return -118; diff --git a/src/kernel/pool.c b/src/kernel/pool.c index c252be566..d85846f64 100644 --- a/src/kernel/pool.c +++ b/src/kernel/pool.c @@ -88,9 +88,9 @@ int get_reservation(const unit * u, const item_type * itype) { reservation *res = u->reservations; - if (itype->rtype == get_resourcetype(R_STONE) && (u_race(u)->flags & RCF_STONEGOLEM)) + if (itype->rtype == get_resourcetype(R_STONE) && (u_race(u)->ec_flags & ECF_STONEGOLEM)) return (u->number * GOLEM_STONE); - if (itype->rtype == get_resourcetype(R_IRON) && (u_race(u)->flags & RCF_IRONGOLEM)) + if (itype->rtype == get_resourcetype(R_IRON) && (u_race(u)->ec_flags & ECF_IRONGOLEM)) return (u->number * GOLEM_IRON); while (res && res->type != itype) res = res->next; diff --git a/src/kernel/race.h b/src/kernel/race.h index 2990c2158..1203eaed2 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -226,11 +226,9 @@ extern "C" { #define RCF_CANSAIL (1<<24) /* Einheit darf Schiffe betreten */ #define RCF_INVISIBLE (1<<25) /* not visible in any report */ #define RCF_SHIPSPEED (1<<26) /* race gets +1 on shipspeed */ -#define RCF_STONEGOLEM (1<<27) /* race gets stonegolem properties */ -#define RCF_IRONGOLEM (1<<28) /* race gets irongolem properties */ +#define RCF_MIGRANTS (1<<27) /* may have migrant units (human bonus) */ +#define RCF_FAMILIAR (1<<28) /* may be a familiar */ #define RCF_ATTACK_MOVED (1<<29) /* may attack if it has moved */ -#define RCF_MIGRANTS (1<<30) /* may have migrant units (human bonus) */ -#define RCF_FAMILIAR (1<<31) /* may be a familiar */ /* Economic flags */ #define ECF_GIVEPERSON (1<<2) /* �bergibt Personen */ @@ -238,6 +236,8 @@ extern "C" { #define ECF_GETITEM (1<<4) /* nimmt Gegenst�nde an */ #define ECF_REC_ETHEREAL (1<<7) /* Rekrutiert aus dem Nichts */ #define ECF_REC_UNLIMITED (1<<8) /* Rekrutiert ohne Limit */ +#define ECF_STONEGOLEM (1<<9) /* race gets stonegolem properties */ +#define ECF_IRONGOLEM (1<<10) /* race gets irongolem properties */ /* Battle-Flags */ #define BF_EQUIPMENT (1<<0) /* Kann Ausr�stung benutzen */ diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 18bdedebc..92112ddb6 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1434,10 +1434,6 @@ static int parse_races(xmlDocPtr doc) rc->flags |= RCF_DRAGON; if (xml_bvalue(node, "shipspeed", false)) rc->flags |= RCF_SHIPSPEED; - if (xml_bvalue(node, "stonegolem", false)) - rc->flags |= RCF_STONEGOLEM; - if (xml_bvalue(node, "irongolem", false)) - rc->flags |= RCF_IRONGOLEM; if (xml_bvalue(node, "giveperson", false)) rc->ec_flags |= ECF_GIVEPERSON; @@ -1449,6 +1445,10 @@ static int parse_races(xmlDocPtr doc) rc->ec_flags |= ECF_REC_ETHEREAL; if (xml_bvalue(node, "recruitunlimited", false)) rc->ec_flags |= ECF_REC_UNLIMITED; + if (xml_bvalue(node, "stonegolem", false)) + rc->ec_flags |= ECF_STONEGOLEM; + if (xml_bvalue(node, "irongolem", false)) + rc->ec_flags |= ECF_IRONGOLEM; if (xml_bvalue(node, "equipment", false)) rc->battle_flags |= BF_EQUIPMENT; /* TODO: invert this flag, so rc_get_or_create gets simpler */ diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c index fd9ef2f19..4e5ec96fc 100644 --- a/src/modules/autoseed.c +++ b/src/modules/autoseed.c @@ -155,7 +155,7 @@ newfaction *read_newfactions(const char *filename) email[0] = '\0'; password[0] = '\0'; - if (sscanf(buf, "%54s %20s %8s %16s %d %d", email, race, lang, + if (sscanf(buf, "%54s %19s %8s %16s %d %d", email, race, lang, password, &subscription, &alliance) < 3) { break; }