- bugfixes for snprintf, warnings for overflowing static buffers

- some English messages
This commit is contained in:
Enno Rehling 2007-09-01 21:52:13 +00:00
parent 7dda1968ee
commit 28fa9e5d81
4 changed files with 557 additions and 441 deletions
src

File diff suppressed because it is too large Load diff

View file

@ -71,6 +71,9 @@ boolean nocr = false;
boolean nonr = false; boolean nonr = false;
boolean noreports = false; boolean noreports = false;
#define WARN_STATIC_BUFFER() \
log_warning(("static buffer too small in %s:%d\n", __FILE__, __LINE__))
const char * g_reportdir; const char * g_reportdir;
const char * visibility[] = { const char * visibility[] = {
"none", "none",
@ -92,12 +95,27 @@ const char *coasts[MAXDIRECTIONS] =
"coast::w" "coast::w"
}; };
int
wrptr(char ** ptr, size_t * size, int bytes)
{
if (bytes<=*size) {
*ptr += bytes;
*size -= bytes;
return 0;
}
else {
*ptr += *size;
*size = 0;
return 1;
}
}
const char * const char *
reportpath(void) reportpath(void)
{ {
static char zText[MAX_PATH]; static char zText[MAX_PATH];
if (g_reportdir) return g_reportdir; if (g_reportdir) return g_reportdir;
return strcat(strcpy(zText, basepath()), "/reports"); return strcat(strcpy(zText, basepath()), "/reports");
} }
static char * static char *
@ -256,7 +274,7 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char * buf, siz
boolean itemcloak = false; boolean itemcloak = false;
static const curse_type * itemcloak_ct = 0; static const curse_type * itemcloak_ct = 0;
static boolean init = false; static boolean init = false;
size_t rsize; int bytes;
if (!init) { if (!init) {
init = true; init = true;
@ -273,10 +291,8 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char * buf, siz
telepath_see = fspecial(f, FS_TELEPATHY); telepath_see = fspecial(f, FS_TELEPATHY);
#endif /* KARMA_MODULE */ #endif /* KARMA_MODULE */
rsize = strlcpy(bufp, unitname(u), size); bytes = strlcpy(bufp, unitname(u), size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize;
bufp += rsize;
if (!isbattle) { if (!isbattle) {
attrib *a_otherfaction = a_find(u->attribs, &at_otherfaction); attrib *a_otherfaction = a_find(u->attribs, &at_otherfaction);
@ -285,116 +301,79 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char * buf, siz
attrib *a = a_find(u->attribs, &at_group); attrib *a = a_find(u->attribs, &at_group);
if (a) { if (a) {
group * g = (group*)a->data.v; group * g = (group*)a->data.v;
rsize = strlcpy(bufp, ", ", size); bytes = strlcpy(bufp, ", ", size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize; bytes = strlcpy(bufp, groupid(g, f), size);
bufp += rsize; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
rsize = strlcpy(bufp, groupid(g, f), size);
if (rsize>size) rsize = size-1;
size -= rsize;
bufp += rsize;
} }
} }
if (getarnt) { if (getarnt) {
rsize = strlcpy(bufp, ", ", size); bytes = strlcpy(bufp, ", ", size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize; bytes = strlcpy(bufp, LOC(f->locale, "anonymous"), size);
bufp += rsize; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
rsize = strlcpy(bufp, LOC(f->locale, "anonymous"), size);
if (rsize>size) rsize = size-1;
size -= rsize;
bufp += rsize;
} else if (a_otherfaction) { } else if (a_otherfaction) {
faction * otherfaction = get_otherfaction(a_otherfaction); faction * otherfaction = get_otherfaction(a_otherfaction);
if (otherfaction) { if (otherfaction) {
rsize = strlcpy(bufp, ", ", size); bytes = strlcpy(bufp, ", ", size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize; bytes = strlcpy(bufp, factionname(otherfaction), size);
bufp += rsize; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
rsize = strlcpy(bufp, factionname(otherfaction), size);
if (rsize>size) rsize = size-1;
size -= rsize;
bufp += rsize;
} }
} }
} else { } else {
if (getarnt) { if (getarnt) {
rsize = strlcpy(bufp, ", ", size); bytes = strlcpy(bufp, ", ", size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize; bytes = strlcpy(bufp, LOC(f->locale, "anonymous"), size);
bufp += rsize; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
rsize = strlcpy(bufp, LOC(f->locale, "anonymous"), size);
if (rsize>size) rsize = size-1;
size -= rsize;
bufp += rsize;
} else { } else {
if (a_otherfaction && alliedunit(u, f, HELP_FSTEALTH)) { if (a_otherfaction && alliedunit(u, f, HELP_FSTEALTH)) {
faction * f = get_otherfaction(a_otherfaction); faction * f = get_otherfaction(a_otherfaction);
bufp += snprintf(bufp, size, ", %s (%s)", factionname(f), factionname(u->faction)); bytes = snprintf(bufp, size, ", %s (%s)", factionname(f), factionname(u->faction));
size = sizeof(buf)-(bufp-buf); if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
} else { } else {
rsize = strlcpy(bufp, ", ", size); bytes = strlcpy(bufp, ", ", size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize; bytes = strlcpy(bufp, factionname(fv), size);
bufp += rsize; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
rsize = strlcpy(bufp, factionname(fv), size);
if (rsize>size) rsize = size-1;
size -= rsize;
bufp += rsize;
} }
} }
} }
} }
rsize = strlcpy(bufp, ", ", size); bytes = strlcpy(bufp, ", ", size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize;
bufp += rsize;
if (u->faction != f && a_fshidden && a_fshidden->data.ca[0] == 1 && effskill(u, SK_STEALTH) >= 6) { if (u->faction != f && a_fshidden && a_fshidden->data.ca[0] == 1 && effskill(u, SK_STEALTH) >= 6) {
rsize = strlcpy(bufp, "? ", size); bytes = strlcpy(bufp, "? ", size);
if (rsize>size) rsize = size-1;
size -= rsize;
bufp += rsize;
} else { } else {
bufp += snprintf(bufp, size, "%d ", u->number); bytes = snprintf(bufp, size, "%d ", u->number);
size = sizeof(buf)-(bufp-buf);
} }
if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
pzTmp = get_racename(u->attribs); pzTmp = get_racename(u->attribs);
if (pzTmp) { if (pzTmp) {
rsize = strlcpy(bufp, pzTmp, size); bytes = strlcpy(bufp, pzTmp, size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize;
bufp += rsize;
if (u->faction==f && fval(u->race, RCF_SHAPESHIFTANY)) { if (u->faction==f && fval(u->race, RCF_SHAPESHIFTANY)) {
rsize = strlcpy(bufp, " (", size); bytes = strlcpy(bufp, " (", size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize; bytes = strlcpy(bufp, racename(f->locale, u, u->race), size);
bufp += rsize; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
rsize = strlcpy(bufp, racename(f->locale, u, u->race), size);
if (rsize>size) rsize = size-1;
size -= rsize;
bufp += rsize;
if (size>1) { if (size>1) {
strcpy(bufp++, ")"); strcpy(bufp++, ")");
--size; --size;
} }
} }
} else { } else {
rsize = strlcpy(bufp, racename(f->locale, u, u->irace), size); bytes = strlcpy(bufp, racename(f->locale, u, u->irace), size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize;
bufp += rsize;
if (u->faction==f && u->irace!=u->race) { if (u->faction==f && u->irace!=u->race) {
rsize = strlcpy(bufp, " (", size); bytes = strlcpy(bufp, " (", size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize; bytes = strlcpy(bufp, racename(f->locale, u, u->race), size);
bufp += rsize; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
rsize = strlcpy(bufp, racename(f->locale, u, u->race), size);
if (rsize>size) rsize = size-1;
size -= rsize;
bufp += rsize;
if (size>1) { if (size>1) {
strcpy(bufp++, ")"); strcpy(bufp++, ")");
--size; --size;
@ -404,45 +383,31 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char * buf, siz
#ifdef HEROES #ifdef HEROES
if (fval(u, UFL_HERO) && (u->faction == f || omniscient(f))) { if (fval(u, UFL_HERO) && (u->faction == f || omniscient(f))) {
rsize = strlcpy(bufp, ", ", size); bytes = strlcpy(bufp, ", ", size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize; bytes = strlcpy(bufp, LOC(f->locale, "hero"), size);
bufp += rsize; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
rsize = strlcpy(bufp, LOC(f->locale, "hero"), size);
if (rsize>size) rsize = size-1;
size -= rsize;
bufp += rsize;
} }
#endif #endif
/* status */ /* status */
if (u->number && (u->faction == f || telepath_see || isbattle)) { if (u->number && (u->faction == f || telepath_see || isbattle)) {
const char * c = locale_string(f->locale, hp_status(u)); const char * c = locale_string(f->locale, hp_status(u));
rsize = strlcpy(bufp, ", ", size); bytes = strlcpy(bufp, ", ", size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize; bytes = strlcpy(bufp, report_kampfstatus(u, f->locale), size);
bufp += rsize; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
rsize = strlcpy(bufp, report_kampfstatus(u, f->locale), size);
if (rsize>size) rsize = size-1;
size -= rsize;
bufp += rsize;
if (c || fval(u, UFL_HUNGER)) { if (c || fval(u, UFL_HUNGER)) {
rsize = strlcpy(bufp, " (", size); bytes = strlcpy(bufp, " (", size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize;
bufp += rsize;
if (c) { if (c) {
rsize = strlcpy(bufp, c, size); bytes = strlcpy(bufp, c, size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize;
bufp += rsize;
} }
if (fval(u, UFL_HUNGER)) { if (fval(u, UFL_HUNGER)) {
if (c) rsize = strlcpy(bufp, ", hungert", size); if (c) bytes = strlcpy(bufp, ", hungert", size);
else rsize = strlcpy(bufp, "hungert", size); else bytes = strlcpy(bufp, "hungert", size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize;
bufp += rsize;
} }
if (size>1) { if (size>1) {
strcpy(bufp++, ")"); strcpy(bufp++, ")");
@ -451,35 +416,25 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char * buf, siz
} }
} }
if (getguard(u)) { if (getguard(u)) {
rsize = strlcpy(bufp, ", ", size); bytes = strlcpy(bufp, ", ", size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize; bytes = strlcpy(bufp, LOC(f->locale, "unit_guards"), size);
bufp += rsize; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
rsize = strlcpy(bufp, LOC(f->locale, "unit_guards"), size);
if (rsize>size) rsize = size-1;
size -= rsize;
bufp += rsize;
} }
if ((b = usiege(u))!=NULL) { if ((b = usiege(u))!=NULL) {
rsize = strlcpy(bufp, ", belagert ", size); bytes = strlcpy(bufp, ", belagert ", size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize; bytes = strlcpy(bufp, buildingname(b), size);
bufp += rsize; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
rsize = strlcpy(bufp, buildingname(b), size);
if (rsize>size) rsize = size-1;
size -= rsize;
bufp += rsize;
} }
dh = 0; dh = 0;
if (u->faction == f || telepath_see) { if (u->faction == f || telepath_see) {
skill * sv; skill * sv;
for (sv = u->skills;sv!=u->skills+u->skill_size;++sv) { for (sv = u->skills;sv!=u->skills+u->skill_size;++sv) {
rsize = spskill(bufp, size, f->locale, u, sv, &dh, 1); bytes = spskill(bufp, size, f->locale, u, sv, &dh, 1);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize;
bufp += rsize;
} }
} }
@ -516,27 +471,23 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char * buf, siz
} }
for (itm=show; itm; itm=itm->next) { for (itm=show; itm; itm=itm->next) {
const char * ic; const char * ic;
int in; int in, bytes;
report_item(u, itm, f, &ic, NULL, &in, false); report_item(u, itm, f, &ic, NULL, &in, false);
if (in==0 || ic==NULL) continue; if (in==0 || ic==NULL) continue;
rsize = strlcpy(bufp, ", ", size); bytes = strlcpy(bufp, ", ", size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize;
bufp += rsize;
if (!dh) { if (!dh) {
bufp += snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_inventory")); bytes = snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_inventory"));
size = sizeof(buf)-(bufp-buf); if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
dh = 1; dh = 1;
} }
if (in == 1) { if (in == 1) {
rsize = strlcpy(bufp, ic, size); bytes = strlcpy(bufp, ic, size);
} else { } else {
rsize = snprintf(bufp, size, "%d %s", in, ic); bytes = snprintf(bufp, size, "%d %s", in, ic);
} }
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize;
bufp += rsize;
} }
if (show!=u->items) while (show) i_free(i_remove(&show, show)); if (show!=u->items) while (show) i_free(i_remove(&show, show));
@ -546,71 +497,64 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char * buf, siz
if (m!=NULL) { if (m!=NULL) {
spell_list *slist = m->spells; spell_list *slist = m->spells;
int t = effskill(u, SK_MAGIC); int t = effskill(u, SK_MAGIC);
bufp += snprintf(bufp, size, ". Aura %d/%d", get_spellpoints(u), max_spellpoints(u->region,u)); int bytes = snprintf(bufp, size, ". Aura %d/%d", get_spellpoints(u), max_spellpoints(u->region,u));
size = sizeof(buf)-(bufp-buf); if (bytes && wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
for (dh=0; slist; slist=slist->next) { for (dh=0; slist; slist=slist->next) {
spell * sp = slist->data; spell * sp = slist->data;
if (sp->level > t) continue; if (sp->level > t) continue;
if (!dh) { if (!dh) {
rsize = snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_spells")); bytes = snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_spells"));
dh = 1; dh = 1;
} else { } else {
rsize = strlcpy(bufp, ", ", size); bytes = strlcpy(bufp, ", ", size);
} }
if (rsize>size) rsize = size-1; if (bytes && wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize; bytes = strlcpy(bufp, spell_name(sp, f->locale), size);
bufp += rsize; if (bytes && wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
rsize = strlcpy(bufp, spell_name(sp, f->locale), size);
if (rsize>size) rsize = size-1;
size -= rsize;
bufp += rsize;
} }
for (i=0; i!=MAXCOMBATSPELLS; ++i) { for (i=0; i!=MAXCOMBATSPELLS; ++i) {
if (get_combatspell(u, i)) break; if (get_combatspell(u, i)) break;
} }
if (i!=MAXCOMBATSPELLS) { if (i!=MAXCOMBATSPELLS) {
bufp += snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_combatspells")); bytes = snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_combatspells"));
size = sizeof(buf)-(bufp-buf); if (bytes && wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
dh = 0; dh = 0;
for (i = 0; i < MAXCOMBATSPELLS; i++){ for (i = 0; i < MAXCOMBATSPELLS; i++){
const spell *sp; const spell *sp;
if (!dh){ if (!dh){
dh = 1; dh = 1;
} else { } else {
rsize = strlcpy(bufp, ", ", size); bytes = strlcpy(bufp, ", ", size);
if (rsize>size) rsize = size-1; if (bytes && wrptr(&bufp, &size, bytes)!=0) {
size -= rsize; WARN_STATIC_BUFFER();
bufp += rsize; }
} }
sp = get_combatspell(u,i); sp = get_combatspell(u,i);
if (sp) { if (sp) {
int sl = get_combatspelllevel(u, i); int sl = get_combatspelllevel(u, i);
rsize = strlcpy(bufp, spell_name(sp, u->faction->locale), size); bytes = strlcpy(bufp, spell_name(sp, u->faction->locale), size);
if (rsize>size) rsize = size-1; if (bytes && wrptr(&bufp, &size, bytes)!=0) {
size -= rsize; WARN_STATIC_BUFFER();
bufp += rsize; }
if (sl > 0) { if (sl > 0) {
bufp += snprintf(bufp, size, " (%d)", sl); bytes = snprintf(bufp, size, " (%d)", sl);
size = sizeof(buf)-(bufp-buf); if (bytes && wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
} }
} else { } else {
rsize = strlcpy(bufp, LOC(f->locale, "nr_nospells"), size); bytes = strlcpy(bufp, LOC(f->locale, "nr_nospells"), size);
if (rsize>size) rsize = size-1; if (bytes && wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize;
bufp += rsize;
} }
} }
} }
} }
#ifdef LASTORDER #ifdef LASTORDER
if (!isbattle && u->lastorder) { if (!isbattle && u->lastorder) {
rsize = buforder(bufp, size, u->lastorder, 0); bytes = buforder(bufp, size, u->lastorder, 0);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize;
bufp += rsize;
} }
#else #else
if (!isbattle) { if (!isbattle) {
@ -619,18 +563,16 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char * buf, siz
for (ord=u->old_orders;ord;ord=ord->next) { for (ord=u->old_orders;ord;ord=ord->next) {
if (is_repeated(ord)) { if (is_repeated(ord)) {
if (printed<ORDERS_IN_NR) { if (printed<ORDERS_IN_NR) {
rsize = buforder(bufp, size, ord, printed++); bytes = buforder(bufp, size, ord, printed++);
size -= rsize; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
bufp += rsize;
} else break; } else break;
} }
} }
if (printed<ORDERS_IN_NR) for (ord=u->orders;ord;ord=ord->next) { if (printed<ORDERS_IN_NR) for (ord=u->orders;ord;ord=ord->next) {
if (is_repeated(ord)) { if (is_repeated(ord)) {
if (printed<ORDERS_IN_NR) { if (printed<ORDERS_IN_NR) {
rsize = buforder(bufp, size, ord, printed++); bytes = buforder(bufp, size, ord, printed++);
size -= rsize; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
bufp += rsize;
} else break; } else break;
} }
} }
@ -641,15 +583,11 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char * buf, siz
str = u_description(u, f->locale); str = u_description(u, f->locale);
if (str) { if (str) {
rsize = strlcpy(bufp, "; ", size); bytes = strlcpy(bufp, "; ", size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize;
bufp += rsize;
rsize = strlcpy(bufp, str, size); bytes = strlcpy(bufp, str, size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize;
bufp += rsize;
i = str[strlen(str) - 1]; i = str[strlen(str) - 1];
} }
@ -661,18 +599,12 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char * buf, siz
} }
pzTmp = uprivate(u); pzTmp = uprivate(u);
if (u->faction == f && pzTmp) { if (u->faction == f && pzTmp) {
rsize = strlcpy(bufp, " (Bem: ", size); bytes = strlcpy(bufp, " (Bem: ", size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize; bytes = strlcpy(bufp, pzTmp, size);
bufp += rsize; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
rsize = strlcpy(bufp, pzTmp, size); bytes = strlcpy(bufp, ")", size);
if (rsize>size) rsize = size-1; if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
size -= rsize;
bufp += rsize;
rsize = strlcpy(bufp, ")", size);
if (rsize>size) rsize = size-1;
size -= rsize;
bufp += rsize;
} }
dh=0; dh=0;
@ -1872,26 +1804,25 @@ eval_resources(struct opstack ** stack, const void * userdata) /* order -> strin
{ {
const faction * report = (const faction*)userdata; const faction * report = (const faction*)userdata;
const struct resource * res = (const struct resource *)opop(stack).v; const struct resource * res = (const struct resource *)opop(stack).v;
static char buf[256]; static char buf[512];
size_t len = sizeof(buf); size_t size = sizeof(buf) - 1;
variant var; variant var;
char * edit = buf; char * bufp = buf;
while (res!=NULL && len > 4) { while (res!=NULL && size > 4) {
const char * rname = resourcename(res->type, (res->number!=1)?NMF_PLURAL:0); const char * rname = resourcename(res->type, (res->number!=1)?NMF_PLURAL:0);
int written = snprintf(edit, len, "%d %s", res->number, LOC(report->locale, rname)); int bytes = snprintf(bufp, size, "%d %s", res->number, LOC(report->locale, rname));
len -= written; if (bytes && wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
edit += written;
res = res->next; res = res->next;
if (res!=NULL && len>2) { if (res!=NULL && size>2) {
strcat(edit, ", "); strcat(bufp, ", ");
edit += 2; bufp += 2;
len -= 2; size -= 2;
} }
} }
*edit = 0; *bufp = 0;
var.v = strcpy(balloc(edit-buf+1), buf); var.v = strcpy(balloc(bufp-buf+1), buf);
opush(stack, var); opush(stack, var);
} }
@ -1903,9 +1834,9 @@ eval_regions(struct opstack ** stack, const void * userdata) /* order -> string
int end, begin = opop(stack).i; int end, begin = opop(stack).i;
const arg_regions * regions = (const arg_regions *)opop(stack).v; const arg_regions * regions = (const arg_regions *)opop(stack).v;
static char buf[256]; static char buf[256];
size_t len = sizeof(buf); size_t size = sizeof(buf) - 1;
variant var; variant var;
char * edit = buf; char * bufp = buf;
if (regions==NULL) { if (regions==NULL) {
end = begin; end = begin;
@ -1915,18 +1846,17 @@ eval_regions(struct opstack ** stack, const void * userdata) /* order -> string
} }
for (i=begin;i<end;++i) { for (i=begin;i<end;++i) {
const char * rname = (const char*)regionname(regions->regions[i], report); const char * rname = (const char*)regionname(regions->regions[i], report);
size_t written = strlcpy(edit, rname, len); int bytes = strlcpy(bufp, rname, size);
len -= written; if (bytes && wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
edit += written;
if (i+1<end && len>2) { if (i+1<end && size>2) {
strcat(edit, ", "); strcat(bufp, ", ");
edit += 2; bufp += 2;
len -= 2; size -= 2;
} }
} }
*edit = 0; *bufp = 0;
var.v = strcpy(balloc(edit-buf+1), buf); var.v = strcpy(balloc(bufp-buf+1), buf);
opush(stack, var); opush(stack, var);
} }
@ -1937,8 +1867,9 @@ eval_trail(struct opstack ** stack, const void * userdata) /* order -> string */
int i, end = 0, begin = 0; int i, end = 0, begin = 0;
const arg_regions * regions = (const arg_regions *)opop(stack).v; const arg_regions * regions = (const arg_regions *)opop(stack).v;
static char buf[256]; static char buf[256];
size_t size = sizeof(buf) - 1;
variant var; variant var;
char * edit = buf; char * bufp = buf;
if (regions!=NULL) { if (regions!=NULL) {
end = regions->nregions-1; end = regions->nregions-1;
@ -1946,17 +1877,20 @@ eval_trail(struct opstack ** stack, const void * userdata) /* order -> string */
region * r = regions->regions[i]; region * r = regions->regions[i];
const char * trail = trailinto(r, report->locale); const char * trail = trailinto(r, report->locale);
const char * rn = f_regionid_s(r, report); const char * rn = f_regionid_s(r, report);
int bytes = snprintf(bufp, size, trail, rn);
if (bytes && wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
edit += snprintf(edit, sizeof(buf)-(edit-buf), trail, rn);
if (i+2<end) { if (i+2<end) {
edit += strlcpy(edit, ", ", sizeof(buf)-(edit-buf)); bytes = strlcpy(bufp, ", ", size);
} else if (i+1<end) { } else if (i+1<end) {
edit += strlcpy(edit, LOC(report->locale, "list_and"), sizeof(buf)-(edit-buf)); bytes = strlcpy(bufp, LOC(report->locale, "list_and"), size);
} } else bytes = 0;
if (bytes && wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
} }
} }
buf[sizeof(buf)-1] = 0; *bufp = 0;
var.v = strcpy(balloc(edit-buf+1), buf); var.v = strcpy(balloc(bufp-buf+1), buf);
opush(stack, var); opush(stack, var);
} }

View file

@ -46,6 +46,7 @@ void lparagraph(struct strlist ** SP, char *s, int indent, char mark);
const char *hp_status(const struct unit * u); const char *hp_status(const struct unit * u);
extern size_t spskill(char * pbuf, size_t siz, const struct locale * lang, const struct unit * u, struct skill * sv, int *dh, int days); /* mapper */ extern size_t spskill(char * pbuf, size_t siz, const struct locale * lang, const struct unit * u, struct skill * sv, int *dh, int days); /* mapper */
extern void spunit(struct strlist ** SP, const struct faction * f, const struct unit * u, int indent, int mode); extern void spunit(struct strlist ** SP, const struct faction * f, const struct unit * u, int indent, int mode);
extern int wrptr(char ** ptr, size_t * size, int bytes);
extern int reports(void); extern int reports(void);
extern int write_reports(struct faction * f, time_t ltime); extern int write_reports(struct faction * f, time_t ltime);

View file

@ -1355,6 +1355,7 @@
<arg name="amount" type="int"/> <arg name="amount" type="int"/>
</type> </type>
<text locale="de">"$unit($mage) kümmert sich um die Verletzten und heilt $int($amount) Verwundete."</text> <text locale="de">"$unit($mage) kümmert sich um die Verletzten und heilt $int($amount) Verwundete."</text>
<text locale="en">"$unit($mage) sees after the wounded and heals $int($amount)."</text>
</message> </message>
<message name="healing_effect_1" section="magic"> <message name="healing_effect_1" section="magic">
@ -1364,6 +1365,7 @@
<arg name="item" type="resource"/> <arg name="item" type="resource"/>
</type> </type>
<text locale="de">"$unit($mage) kümmert sich um die Verletzten und benutzt ein $resource($item,1), um den Zauber zu verstärken. $int($amount) Verwundete werden geheilt."</text> <text locale="de">"$unit($mage) kümmert sich um die Verletzten und benutzt ein $resource($item,1), um den Zauber zu verstärken. $int($amount) Verwundete werden geheilt."</text>
<text locale="en">"$unit($mage) sees after the wounded and heals $int($amount). A $resource($item,1) improves the spell."</text>
</message> </message>
<message name="sp_eternizewall_effect" section="magic"> <message name="sp_eternizewall_effect" section="magic">
@ -8269,6 +8271,7 @@
<arg name="command" type="order"/> <arg name="command" type="order"/>
</type> </type>
<text locale="de">"$unit($unit) in $region($region): '$order($command)' - In dieser Region gibt es keine Brücken uns Straßen mehr zu bauen."</text> <text locale="de">"$unit($unit) in $region($region): '$order($command)' - In dieser Region gibt es keine Brücken uns Straßen mehr zu bauen."</text>
<text locale="en">"$unit($unit) in $region($region): '$order($command)' - the roads and bridges in this region are complete."</text>
</message> </message>
<message name="error_build_skill_low" section="errors"> <message name="error_build_skill_low" section="errors">
@ -8316,7 +8319,11 @@
<type> <type>
<arg name="faction" type="faction"/> <arg name="faction" type="faction"/>
</type> </type>
<text locale="de">"Achtung: $faction($faction) hat einige Zeit keine Züge eingeschickt und könnte dadurch in Kürze aus dem Spiel ausscheiden"</text> <text locale="de">"Achtung: $faction($faction) hat einige Zeit keine
Züge eingeschickt und könnte dadurch in Kürze aus dem Spiel
ausscheiden."</text>
<text locale="en">"Warning: $faction($faction) has not been sending in
orders for some time and may be leaving the game soon."</text>
</message> </message>
</messages> </messages>