- Do not trust strcheck() in Release

- Nobody needs strnzcpy() anymore, use bsdstring.h
This commit is contained in:
Enno Rehling 2007-02-25 18:49:28 +00:00
parent 034753d9b8
commit 426a8a34f2
7 changed files with 55 additions and 58 deletions

View File

@ -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

View File

@ -69,6 +69,7 @@
#include <util/translation.h>
#include <util/umlaut.h>
#include <util/xml.h>
#include <util/bsdstring.h>
/* libxml includes */
#include <libxml/tree.h>
@ -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;
}

View File

@ -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 *

View File

@ -54,6 +54,7 @@
/* util includes */
#include <util/attrib.h>
#include <util/base36.h>
#include <util/bsdstring.h>
#include <util/event.h>
#include <util/goodies.h>
#include <util/resolve.h>
@ -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!! */

View File

@ -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

View File

@ -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

View File

@ -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()