diff --git a/src/kernel/pathfinder.c b/src/kernel/pathfinder.c index 0c9007677..59f977f61 100644 --- a/src/kernel/pathfinder.c +++ b/src/kernel/pathfinder.c @@ -141,7 +141,7 @@ static region **internal_path_find(region * handle_start, const region * target, int maxlen, bool(*allowed) (const region *, const region *)) { static region *path[MAXDEPTH + 2]; /* STATIC_RETURN: used for return, not across calls */ - direction_t d; + direction_t d = MAXDIRECTIONS; node *root = new_node(handle_start, 0, NULL); node **handle_end = &root->next; node *n = root; @@ -179,7 +179,7 @@ static region **internal_path_find(region * handle_start, const region * target, n = n->next; } free_nodes(root); - if (n) { + if (d != MAXDIRECTIONS) { return path; } return NULL; diff --git a/src/laws.c b/src/laws.c index 113cd6252..eb483aae7 100644 --- a/src/laws.c +++ b/src/laws.c @@ -1702,7 +1702,7 @@ static int rename_cmd(unit * u, order * ord, char **s, const char *s2) } static bool try_rename(unit *u, building *b, order *ord) { - unit *owner = b ? building_owner(b) : 0; + unit *owner = b ? building_owner(b) : NULL; bool foreign = !(owner && owner->faction == u->faction); if (!b) { @@ -1732,12 +1732,12 @@ static bool try_rename(unit *u, building *b, order *ord) { msg_message("renamed_building_notseen", "building region", b, u->region)); } - if (owner != u) { - cmistake(u, ord, 148, MSG_PRODUCE); - return false; - } } } + if (owner && owner->faction != u->faction) { + cmistake(u, ord, 148, MSG_PRODUCE); + return false; + } return true; } diff --git a/src/laws.test.c b/src/laws.test.c index 795656706..5dff45a92 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1355,6 +1355,24 @@ static void test_name_cmd(CuTest *tc) { test_teardown(); } +static void test_name_foreign_cmd(CuTest *tc) { + building *b; + faction *f; + region *r; + unit *u; + + test_setup(); + u = test_create_unit(f = test_create_faction(NULL), r = test_create_region(0, 0, NULL)); + b = test_create_building(u->region, NULL); + u->thisorder = create_order(K_NAME, f->locale, "%s %s %s Hodor", + LOC(f->locale, parameters[P_FOREIGN]), + LOC(f->locale, parameters[P_BUILDING]), + itoa36(b->no)); + name_cmd(u, u->thisorder); + CuAssertStrEquals(tc, "Hodor", b->name); + test_teardown(); +} + static void test_name_cmd_2274(CuTest *tc) { unit *u1, *u2, *u3; faction *f; @@ -2155,6 +2173,7 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_nmr_warnings); SUITE_ADD_TEST(suite, test_ally_cmd); SUITE_ADD_TEST(suite, test_name_cmd); + SUITE_ADD_TEST(suite, test_name_foreign_cmd); SUITE_ADD_TEST(suite, test_banner_cmd); SUITE_ADD_TEST(suite, test_email_cmd); SUITE_ADD_TEST(suite, test_name_cmd_2274);