diff --git a/src/common/kernel/alliance.c b/src/common/kernel/alliance.c index ed664b1a1..eca88cafe 100644 --- a/src/common/kernel/alliance.c +++ b/src/common/kernel/alliance.c @@ -227,18 +227,19 @@ setalliance(struct faction * f, alliance * al) const char * alliancename(const alliance * al) { - typedef char name[OBJECTIDSIZE + 1]; - static name idbuf[8]; - static int nextbuf = 0; + typedef char name[OBJECTIDSIZE + 1]; + static name idbuf[8]; + static int nextbuf = 0; - char *buf = idbuf[(++nextbuf) % 8]; + char *ibuf = idbuf[(++nextbuf) % 8]; - if (al && al->name) { - sprintf(buf, "%s (%s)", strcheck(al->name, NAMESIZE), itoa36(al->id)); - } else { - return NULL; - } - return buf; + if (al && al->name) { + snprintf(ibuf, sizeof(name), "%s (%s)", strcheck(al->name, NAMESIZE), itoa36(al->id)); + ibuf[sizeof(name)] = 0; + } else { + return NULL; + } + return ibuf; } void diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index 2530c777e..eb74fd190 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -69,6 +69,7 @@ #include #include #include +#include /* libxml includes */ #include @@ -96,14 +97,6 @@ const struct race * new_race[MAXRACES]; boolean sqlpatch = false; int turn; -char * -strnzcpy(char * dst, const char *src, size_t len) -{ - strncpy(dst, src, len); - dst[len]=0; - return dst; -} - static attrib_type at_creator = { "creator" /* Rest ist NULL; temporäres, nicht alterndes Attribut */ @@ -1190,7 +1183,7 @@ strcheck (const char *s, size_t maxlen) assert(maxlen < 16 * 1024); log_warning(("[strcheck] String wurde auf %d Zeichen verkürzt:\n%s\n", (int)maxlen, s)); - strnzcpy(buffer, s, maxlen); + strlcpy(buffer, s, maxlen); return buffer; } return s; @@ -1782,24 +1775,24 @@ freestrlist (strlist * s) boolean lomem = false; /* - Namen der Strukturen -------------------------------------- */ -typedef char name[OBJECTIDSIZE + 1]; +typedef char name[OBJECTIDSIZE+1]; static name idbuf[8]; static int nextbuf = 0; char * estring(const char *s) { - char *buf = idbuf[(++nextbuf) % 8]; + char *ibuf = idbuf[(++nextbuf) % 8]; char *r; - strcpy(buf,s); - r = buf; + strlcpy(ibuf, s, sizeof(name)); + r = ibuf; - while(*buf) { - if(*buf == ' ') { - *buf = '~'; + while (*ibuf) { + if(*ibuf == ' ') { + *ibuf = '~'; } - buf++; + ibuf++; } return r; } @@ -1807,17 +1800,17 @@ estring(const char *s) char * cstring(const char *s) { - char *buf = idbuf[(++nextbuf) % 8]; + char *ibuf = idbuf[(++nextbuf) % 8]; char *r; - strcpy(buf,s); - r = buf; + strlcpy(ibuf,s, sizeof(name)); + r = ibuf; - while(*buf) { - if(*buf == '~') { - *buf = ' '; + while (*ibuf) { + if (*ibuf == '~') { + *ibuf = ' '; } - buf++; + ibuf++; } return r; } @@ -1825,10 +1818,11 @@ cstring(const char *s) const char * buildingname (const building * b) { - char *buf = idbuf[(++nextbuf) % 8]; + char *ibuf = idbuf[(++nextbuf) % 8]; - sprintf(buf, "%s (%s)", strcheck(b->name, NAMESIZE), itoa36(b->no)); - return buf; + snprintf(ibuf, sizeof(ibuf), "%s (%s)", strcheck(b->name, NAMESIZE), itoa36(b->no)); + ibuf[sizeof(name)] = 0; + return ibuf; } building * @@ -1858,7 +1852,8 @@ const char * unitname(const unit * u) { char *ubuf = idbuf[(++nextbuf) % 8]; - sprintf(ubuf, "%s (%s)", strcheck(u->name, NAMESIZE), itoa36(u->no)); + snprintf(ubuf, sizeof(name), "%s (%s)", strcheck(u->name, NAMESIZE), itoa36(u->no)); + ubuf[sizeof(name)] = 0; return ubuf; } diff --git a/src/common/kernel/faction.c b/src/common/kernel/faction.c index 6c097508c..382bbac92 100644 --- a/src/common/kernel/faction.c +++ b/src/common/kernel/faction.c @@ -62,18 +62,19 @@ random_unit_in_faction(const faction *f) const char * factionname(const faction * f) { - typedef char name[OBJECTIDSIZE + 1]; + typedef char name[OBJECTIDSIZE+1]; static name idbuf[8]; static int nextbuf = 0; - char *buf = idbuf[(++nextbuf) % 8]; + char *ibuf = idbuf[(++nextbuf) % 8]; if (f && f->name) { - sprintf(buf, "%s (%s)", strcheck(f->name, NAMESIZE), itoa36(f->no)); + snprintf(ibuf, sizeof(name), "%s (%s)", strcheck(f->name, NAMESIZE), itoa36(f->no)); + ibuf[sizeof(name)] = 0; } else { - sprintf(buf, "Unbekannte Partei (?)"); + strcpy(ibuf, "Unbekannte Partei (?)"); } - return buf; + return ibuf; } void * diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index acbd7cfcf..e93cdd244 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -54,6 +54,7 @@ /* util includes */ #include #include +#include #include #include #include @@ -533,11 +534,10 @@ unitorders(FILE * F, struct faction * f) static faction * factionorders(void) { - char b[16]; - char * fid = strnzcpy(b, getstrtoken(), 15); - const char * pass = getstrtoken(); - faction *f = NULL; + char fid[16]; + faction * f = NULL; + strlcpy(fid, getstrtoken(), sizeof(fid)); #ifdef FUZZY_BASE36 int id = atoi36(fid); if (id!=0) f = findfaction(id); @@ -550,6 +550,7 @@ factionorders(void) #endif if (f!=NULL) { + const char * pass = getstrtoken(); /* Kontrolliere, ob das Passwort richtig eingegeben wurde. Es * muß in "Gänsefüßchen" stehen!! */ diff --git a/src/common/kernel/ship.c b/src/common/kernel/ship.c index 5c4835a40..d65cbf810 100644 --- a/src/common/kernel/ship.c +++ b/src/common/kernel/ship.c @@ -205,12 +205,12 @@ destroy_ship(ship * sh) const char * shipname(const ship * sh) { - typedef char name[OBJECTIDSIZE + 1]; - static name idbuf[8]; - static int nextbuf = 0; - char *buf = idbuf[(++nextbuf) % 8]; - sprintf(buf, "%s (%s)", strcheck(sh->name, NAMESIZE), itoa36(sh->no)); - return buf; + typedef char name[OBJECTIDSIZE + 1]; + static name idbuf[8]; + static int nextbuf = 0; + char *ibuf = idbuf[(++nextbuf) % 8]; + sprintf(ibuf, "%s (%s)", strcheck(sh->name, NAMESIZE), itoa36(sh->no)); + return ibuf; } int diff --git a/src/config.h b/src/config.h index 49573202e..ecd3bd9b8 100644 --- a/src/config.h +++ b/src/config.h @@ -252,7 +252,6 @@ extern char * strdup(const char *s); #ifndef INLINE_FUNCTION # define INLINE_FUNCTION #endif -/* this function must be implemented in a .o file */ -extern char * strnzcpy(char * dst, const char *src, size_t len); + #endif diff --git a/src/scripts/wdw-run.lua b/src/scripts/wdw-run.lua index 6bf37478a..4e6b52e6a 100644 --- a/src/scripts/wdw-run.lua +++ b/src/scripts/wdw-run.lua @@ -18,14 +18,14 @@ function process(orders) -- run the turn: + plan_monsters() + process_orders() + -- create new monsters: spawn_dragons() spawn_undead() -- (no more braineaters) spawn_braineaters(0.25) - plan_monsters() - process_orders() - -- post-turn updates: update_guards() update_scores()