diff --git a/src/common/gamecode/randenc.c b/src/common/gamecode/randenc.c index d68f2a947..9f67741b9 100644 --- a/src/common/gamecode/randenc.c +++ b/src/common/gamecode/randenc.c @@ -245,7 +245,7 @@ find_manual(region * r, unit * u) break; } - sprintf(zLocation, "manual_location_%d", rng_int() % 4); + sprintf(zLocation, "manual_location_%d", (int)(rng_int() % 4)); sprintf(zBook, "manual_title_%s", skillnames[skill]); msg = msg_message("find_manual", "unit location book", u, zLocation, zBook); diff --git a/src/common/kernel/building.c b/src/common/kernel/building.c index 4cb883446..1be94a09c 100644 --- a/src/common/kernel/building.c +++ b/src/common/kernel/building.c @@ -520,6 +520,24 @@ buildingeffsize(const building * b, boolean img) return n; } +const xmlChar * +write_buildingname(const building * b, xmlChar * ibuf, size_t size) +{ + snprintf((char*)ibuf, size, "%s (%s)", b->name, itoa36(b->no)); + ibuf[size-1] = 0; + return ibuf; +} + +const xmlChar * +buildingname(const building * b) +{ + typedef char name[OBJECTIDSIZE + 1]; + static name idbuf[8]; + static int nextbuf = 0; + char *ibuf = idbuf[(++nextbuf) % 8]; + return write_buildingname(b, (xmlChar*)ibuf, sizeof(name)); +} + unit * buildingowner(const region * r, const building * b) { diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index c0a35c070..eae62b279 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -1602,21 +1602,6 @@ cstring(const char *s) return cstring_i(ibuf); } -const xmlChar * -write_buildingname(const building * b, xmlChar * ibuf, size_t size) -{ - snprintf((char*)ibuf, sizeof(name), "%s (%s)", b->name, itoa36(b->no)); - ibuf[sizeof(name)-1] = 0; - return ibuf; -} - -const xmlChar * -buildingname(const building * b) -{ - char *ibuf = idbuf[(++nextbuf) % 8]; - return write_buildingname(b, (xmlChar*)ibuf, sizeof(name)); -} - building * largestbuilding (const region * r, boolean img) { diff --git a/src/common/kernel/ship.c b/src/common/kernel/ship.c index 271cd3bcb..fd1875df0 100644 --- a/src/common/kernel/ship.c +++ b/src/common/kernel/ship.c @@ -198,15 +198,22 @@ destroy_ship(ship * sh) handle_event(sh->attribs, "destroy", sh); } -const char * +const xmlChar * +write_shipname(const ship * sh, xmlChar * ibuf, size_t size) +{ + snprintf((char*)ibuf, size, "%s (%s)", sh->name, itoa36(sh->no)); + ibuf[size-1] = 0; + return ibuf; +} + +const xmlChar * shipname(const ship * sh) { typedef char name[OBJECTIDSIZE + 1]; static name idbuf[8]; static int nextbuf = 0; char *ibuf = idbuf[(++nextbuf) % 8]; - sprintf(ibuf, "%s (%s)", sh->name, itoa36(sh->no)); - return ibuf; + return write_shipname(sh, (xmlChar*)ibuf, sizeof(name)); } int diff --git a/src/common/kernel/ship.h b/src/common/kernel/ship.h index 34bcdf137..a61d92747 100644 --- a/src/common/kernel/ship.h +++ b/src/common/kernel/ship.h @@ -87,7 +87,8 @@ extern int shipcapacity(const struct ship * sh); extern void getshipweight(const struct ship * sh, int *weight, int *cabins); extern ship *new_ship(const struct ship_type * stype, const struct locale * lang, struct region * r); -extern const char *shipname(const struct ship * sh); +extern const xmlChar *shipname(const struct ship * sh); +extern const xmlChar *write_shipname(const struct ship * sh, xmlChar * buffer, size_t size); extern struct ship *findship(int n); extern struct ship *findshipr(const struct region *r, int n); diff --git a/src/common/spells/spells.c b/src/common/spells/spells.c index ede3a5997..49c6a9cba 100644 --- a/src/common/spells/spells.c +++ b/src/common/spells/spells.c @@ -670,7 +670,7 @@ sp_destroy_magic(castorder *co) building *b; b = pa->param[0]->data.b; ap = &b->attribs; - strcpy(ts, buildingname(b)); + write_buildingname(b, ts, sizeof(ts)); break; } case SPP_SHIP: @@ -678,7 +678,7 @@ sp_destroy_magic(castorder *co) ship *sh; sh = pa->param[0]->data.sh; ap = &sh->attribs; - strcpy(ts, shipname(sh)); + write_shipname(sh, ts, sizeof(ts)); break; } default: @@ -690,7 +690,7 @@ sp_destroy_magic(castorder *co) if (succ) { ADDMSG(&mage->faction->msgs, msg_message( "destroy_magic_effect", "unit region command succ target", - mage, mage->region, co->order, succ, strdup(ts))); + mage, mage->region, co->order, succ, ts)); } else { ADDMSG(&mage->faction->msgs, msg_message( "destroy_magic_noeffect", "unit region command",