forked from github/server
- Do not trust strcheck() in Release
- Nobody needs strnzcpy() anymore, use bsdstring.h
This commit is contained in:
parent
034753d9b8
commit
426a8a34f2
|
@ -231,14 +231,15 @@ alliancename(const alliance * al)
|
|||
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));
|
||||
snprintf(ibuf, sizeof(name), "%s (%s)", strcheck(al->name, NAMESIZE), itoa36(al->id));
|
||||
ibuf[sizeof(name)] = 0;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
return buf;
|
||||
return ibuf;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 *
|
||||
|
|
|
@ -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!! */
|
||||
|
||||
|
|
|
@ -208,9 +208,9 @@ 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;
|
||||
char *ibuf = idbuf[(++nextbuf) % 8];
|
||||
sprintf(ibuf, "%s (%s)", strcheck(sh->name, NAMESIZE), itoa36(sh->no));
|
||||
return ibuf;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue