From 13a019335e179186e34a7229057786f9f27a8496 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 27 Jun 2007 20:51:56 +0000 Subject: [PATCH] bugs found with gcc --- src/common/kernel/battle.c | 4 ++-- src/common/kernel/faction.c | 3 ++- src/common/kernel/race.c | 13 +++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index 7c9ac0879..18595bde2 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -3284,9 +3284,9 @@ simplename(region * r) { int i; static char name[17]; - const char * cp = rname(r, NULL); + const xmlChar * cp = rname(r, NULL); for (i=0;*cp && i!=16;++i, ++cp) { - int c = *(unsigned char*)cp; + int c = *cp; while (c && !isalpha(c) && !isspace(c)) { ++cp; c = *(unsigned char*)cp; diff --git a/src/common/kernel/faction.c b/src/common/kernel/faction.c index a62f78d0d..bb752996e 100644 --- a/src/common/kernel/faction.c +++ b/src/common/kernel/faction.c @@ -106,6 +106,7 @@ addfaction(const char *email, const xmlChar * password, { faction * f = calloc(sizeof(faction), 1); const char * pass = itoa36(rng_int()); + char buf[128]; assert(frace && frace != new_race[RC_ORC]); @@ -135,7 +136,7 @@ addfaction(const char *email, const xmlChar * password, addlist(&factions, f); fhash(f); - sprintf(buf, "%s %s", LOC(loc, "factiondefault"), factionid(f)); + snprintf(buf, sizeof(buf), "%s %s", LOC(loc, "factiondefault"), factionid(f)); set_string(&f->name, (const xmlChar*)buf); return f; diff --git a/src/common/kernel/race.c b/src/common/kernel/race.c index d9b1b6bcc..175677fa8 100644 --- a/src/common/kernel/race.c +++ b/src/common/kernel/race.c @@ -45,6 +45,7 @@ /* util includes */ #include +#include #include #include @@ -290,12 +291,12 @@ racename(const struct locale *loc, const unit *u, const race * rc) const char * prefix = raceprefix(u); if (prefix!=NULL) { - static char lbuf[80]; - char * s = lbuf; - strcpy(lbuf, locale_string(loc, mkname("prefix", prefix))); - s += strlen(lbuf); - strcpy(s, LOC(loc, rc_name(rc, u->number != 1))); - s[0] = (char)tolower(s[0]); + static xmlChar lbuf[80]; + xmlChar * s = lbuf; + s += xstrlcpy(lbuf, LOC(loc, mkname("prefix", prefix)), sizeof(lbuf)); + xstrlcpy(s, LOC(loc, rc_name(rc, u->number != 1)), sizeof(lbuf)-(s-lbuf)); + assert(s[0]<=0x7F || !"unicode/not implemented"); + s[0] = (xmlChar)tolower(s[0]); return lbuf; } return LOC(loc, rc_name(rc, u->number != 1));