Merge branch 'master' into develop

This commit is contained in:
Enno Rehling 2017-11-19 03:13:46 +01:00
commit d670d04ef8
7 changed files with 47 additions and 6 deletions

View File

@ -853,8 +853,6 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
stream_printf(out, "\"%s\";Typ\n", stream_printf(out, "\"%s\";Typ\n",
translate(zRace, LOC(f->locale, zRace))); translate(zRace, LOC(f->locale, zRace)));
if (u->faction == f && irace != u_race(u)) { if (u->faction == f && irace != u_race(u)) {
assert(skill_enabled(SK_STEALTH)
|| !"we're resetting this on load, so.. ircase should never be used");
zRace = rc_name_s(u_race(u), NAME_PLURAL); zRace = rc_name_s(u_race(u), NAME_PLURAL);
stream_printf(out, "\"%s\";wahrerTyp\n", stream_printf(out, "\"%s\";wahrerTyp\n",
translate(zRace, LOC(f->locale, zRace))); translate(zRace, LOC(f->locale, zRace)));

View File

@ -509,7 +509,7 @@ unit *read_unit(gamedata *data)
u_setrace(u, rc); u_setrace(u, rc);
READ_TOK(data->store, rname, sizeof(rname)); READ_TOK(data->store, rname, sizeof(rname));
if (rname[0] && skill_enabled(SK_STEALTH)) if (rname[0])
u->irace = rc_find(rname); u->irace = rc_find(rname);
else else
u->irace = NULL; u->irace = NULL;

View File

@ -1,5 +1,6 @@
#include <platform.h> #include <platform.h>
#include <kernel/config.h> #include <kernel/config.h>
#include <kernel/race.h>
#include <util/attrib.h> #include <util/attrib.h>
#include <util/gamedata.h> #include <util/gamedata.h>
#include <attributes/key.h> #include <attributes/key.h>
@ -51,6 +52,7 @@ static void test_readwrite_unit(CuTest * tc)
struct unit *u; struct unit *u;
struct region *r; struct region *r;
struct faction *f; struct faction *f;
struct race *irace;
int fno; int fno;
test_setup(); test_setup();
@ -60,6 +62,12 @@ static void test_readwrite_unit(CuTest * tc)
u = test_create_unit(f, r); u = test_create_unit(f, r);
unit_setname(u, " Hodor "); unit_setname(u, " Hodor ");
CuAssertStrEquals(tc, " Hodor ", u->_name); CuAssertStrEquals(tc, " Hodor ", u->_name);
enable_skill(SK_STEALTH, false);
irace = test_create_race("halfling");
CuAssertTrue(tc, playerrace(irace));
u->irace = irace;
CuAssertTrue(tc, irace == u_irace(u));
mstream_init(&data.strm); mstream_init(&data.strm);
gamedata_init(&data, &store, RELEASE_VERSION); gamedata_init(&data, &store, RELEASE_VERSION);
write_unit(&data, u); write_unit(&data, u);
@ -74,6 +82,7 @@ static void test_readwrite_unit(CuTest * tc)
CuAssertPtrNotNull(tc, u); CuAssertPtrNotNull(tc, u);
CuAssertPtrEquals(tc, f, u->faction); CuAssertPtrEquals(tc, f, u->faction);
CuAssertStrEquals(tc, "Hodor", u->_name); CuAssertStrEquals(tc, "Hodor", u->_name);
CuAssertTrue(tc, irace == u_irace(u));
CuAssertPtrEquals(tc, 0, u->region); CuAssertPtrEquals(tc, 0, u->region);
mstream_done(&data.strm); mstream_done(&data.strm);

View File

@ -1063,7 +1063,7 @@ void clone_men(const unit * u, unit * dst, int n)
transfer_curse(u, dst, n); transfer_curse(u, dst, n);
} }
set_number(dst, dst->number + n); set_number(dst, dst->number + n);
dst->hp += u->hp * n / u->number; dst->hp += (long)u->hp * n / u->number;
assert(dst->hp >= dst->number); assert(dst->hp >= dst->number);
/* TODO: Das ist schnarchlahm! und gehoert nicht hierhin */ /* TODO: Das ist schnarchlahm! und gehoert nicht hierhin */
a = a_find(dst->attribs, &at_effect); a = a_find(dst->attribs, &at_effect);

View File

@ -544,6 +544,25 @@ static void test_unlimited_units(CuTest *tc) {
test_cleanup(); test_cleanup();
} }
static void test_clone_men_bug_2386(CuTest *tc) {
unit *u1, *u2;
region *r;
faction *f;
test_setup();
r = test_create_region(0, 0, NULL);
f = test_create_faction(NULL);
u1 = test_create_unit(f, r);
scale_number(u1, 8237);
u1->hp = 39 * u1->number;
u2 = test_create_unit(f, r);
scale_number(u2, 0);
clone_men(u1, u2, 8100);
CuAssertIntEquals(tc, 8100, u2->number);
CuAssertIntEquals(tc, u2->number * 39, u2->hp);
test_cleanup();
}
static void test_clone_men(CuTest *tc) { static void test_clone_men(CuTest *tc) {
unit *u1, *u2; unit *u1, *u2;
region *r; region *r;
@ -597,6 +616,7 @@ CuSuite *get_unit_suite(void)
SUITE_ADD_TEST(suite, test_unit_name_from_race); SUITE_ADD_TEST(suite, test_unit_name_from_race);
SUITE_ADD_TEST(suite, test_update_monster_name); SUITE_ADD_TEST(suite, test_update_monster_name);
SUITE_ADD_TEST(suite, test_clone_men); SUITE_ADD_TEST(suite, test_clone_men);
SUITE_ADD_TEST(suite, test_clone_men_bug_2386);
SUITE_ADD_TEST(suite, test_transfermen); SUITE_ADD_TEST(suite, test_transfermen);
SUITE_ADD_TEST(suite, test_remove_unit); SUITE_ADD_TEST(suite, test_remove_unit);
SUITE_ADD_TEST(suite, test_remove_empty_units); SUITE_ADD_TEST(suite, test_remove_empty_units);

View File

@ -177,11 +177,15 @@ char *parse_token(const char **str, char *lbuf, size_t buflen)
++ctoken; ++ctoken;
} }
else { else {
if (cursor - buflen < lbuf - len) {
*cursor++ = *ctoken++; *cursor++ = *ctoken++;
} }
} }
}
else if (utf8_character == SPACE_REPLACEMENT) { else if (utf8_character == SPACE_REPLACEMENT) {
if (cursor - buflen < lbuf - len) {
*cursor++ = ' '; *cursor++ = ' ';
}
++ctoken; ++ctoken;
} }
else if (utf8_character == ESCAPE_CHAR) { else if (utf8_character == ESCAPE_CHAR) {

View File

@ -28,6 +28,15 @@ static void test_parse_token(CuTest *tc) {
CuAssertPtrEquals(tc, NULL, (void *)tok); CuAssertPtrEquals(tc, NULL, (void *)tok);
} }
static void test_parse_token_bug_2381(CuTest *tc) {
const char *stok, *s = "Bitte~wechselt~auf~die~trireme~3im9,~sobald~eine~Crew~da~ist,~geht~es~los~:)";
char token[64];
stok = s;
stok = parse_token(&stok, token, sizeof(token));
CuAssertTrue(tc, strlen(token) < sizeof(token));
}
static void test_parse_token_limit(CuTest *tc) { static void test_parse_token_limit(CuTest *tc) {
char lbuf[8]; char lbuf[8];
const char *tok; const char *tok;
@ -117,6 +126,7 @@ CuSuite *get_parser_suite(void)
SUITE_ADD_TEST(suite, test_atoip); SUITE_ADD_TEST(suite, test_atoip);
SUITE_ADD_TEST(suite, test_skip_token); SUITE_ADD_TEST(suite, test_skip_token);
SUITE_ADD_TEST(suite, test_parse_token); SUITE_ADD_TEST(suite, test_parse_token);
SUITE_ADD_TEST(suite, test_parse_token_bug_2381);
SUITE_ADD_TEST(suite, test_parse_token_limit); SUITE_ADD_TEST(suite, test_parse_token_limit);
SUITE_ADD_TEST(suite, test_parse_token_limit_utf8); SUITE_ADD_TEST(suite, test_parse_token_limit_utf8);
SUITE_ADD_TEST(suite, test_gettoken); SUITE_ADD_TEST(suite, test_gettoken);