rename strlcpy->str_strlcpy, etc.

This commit is contained in:
Enno Rehling 2017-12-30 19:49:21 +01:00
parent 23ff404d2e
commit a8140f1dc9
24 changed files with 218 additions and 217 deletions

View file

@ -192,7 +192,7 @@ static char *sidename(side * s)
static char sidename_buf[4][SIDENAMEBUFLEN]; /* STATIC_RESULT: used for return, not across calls */ static char sidename_buf[4][SIDENAMEBUFLEN]; /* STATIC_RESULT: used for return, not across calls */
bufno = bufno % 4; bufno = bufno % 4;
strlcpy(sidename_buf[bufno], factionname(s->stealthfaction ? s->stealthfaction : s->faction), SIDENAMEBUFLEN); str_strlcpy(sidename_buf[bufno], factionname(s->stealthfaction ? s->stealthfaction : s->faction), SIDENAMEBUFLEN);
return sidename_buf[bufno++]; return sidename_buf[bufno++];
} }
@ -202,7 +202,7 @@ static const char *sideabkz(side * s, bool truename)
const faction *f = (s->stealthfaction const faction *f = (s->stealthfaction
&& !truename) ? s->stealthfaction : s->faction; && !truename) ? s->stealthfaction : s->faction;
strlcpy(sideabkz_buf, itoa36(f->no), sizeof(sideabkz_buf)); str_strlcpy(sideabkz_buf, itoa36(f->no), sizeof(sideabkz_buf));
return sideabkz_buf; return sideabkz_buf;
} }
@ -2896,10 +2896,10 @@ static void print_header(battle * b)
for (df = s->fighters; df; df = df->next) { for (df = s->fighters; df; df = df->next) {
if (is_attacker(df)) { if (is_attacker(df)) {
if (first) { if (first) {
strlcpy(bufp, ", ", size); str_strlcpy(bufp, ", ", size);
} }
if (lastf) { if (lastf) {
strlcpy(bufp, lastf, size); str_strlcpy(bufp, lastf, size);
first = true; first = true;
} }
if (seematrix(f, s)) if (seematrix(f, s))

View file

@ -6,11 +6,12 @@
#include <kernel/config.h> #include <kernel/config.h>
#include <kernel/jsonconf.h> #include <kernel/jsonconf.h>
#include <util/bsdstring.h>
#include <util/log.h> #include <util/log.h>
#include <util/language.h> #include <util/language.h>
#include <util/nrmessage.h> #include <util/nrmessage.h>
#include <util/path.h> #include <util/path.h>
#include <util/strings.h>
#include <cJSON.h> #include <cJSON.h>
@ -53,7 +54,7 @@ int config_parse(const char *json)
if (xp >= ep) break; if (xp >= ep) break;
} }
xp = (ep > json + 10) ? ep - 10 : json; xp = (ep > json + 10) ? ep - 10 : json;
strlcpy(buffer, xp, sizeof(buffer)); str_strlcpy(buffer, xp, sizeof(buffer));
buffer[9] = 0; buffer[9] = 0;
log_error("json parse error in line %d, position %d, near `%s`\n", line, ep - lp, buffer); log_error("json parse error in line %d, position %d, near `%s`\n", line, ep - lp, buffer);
} }

View file

@ -530,7 +530,7 @@ static const char * relpath(char *buf, size_t sz, const char *path) {
path_join(g_basedir, path, buf, sz); path_join(g_basedir, path, buf, sz);
} }
else { else {
strlcpy(buf, path, sz); str_strlcpy(buf, path, sz);
} }
return buf; return buf;
} }

View file

@ -106,7 +106,7 @@ char* get_command(const order *ord, const struct locale *lang, char *sbuffer, si
const char *str = (const char *)LOC(lang, keyword(kwd)); const char *str = (const char *)LOC(lang, keyword(kwd));
assert(str); assert(str);
if (text) --size; if (text) --size;
bytes = (int)strlcpy(bufp, str, size); bytes = (int)str_strlcpy(bufp, str, size);
if (wrptr(&bufp, &size, bytes) != 0) { if (wrptr(&bufp, &size, bytes) != 0) {
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
@ -117,7 +117,7 @@ char* get_command(const order *ord, const struct locale *lang, char *sbuffer, si
} }
} }
if (text) { if (text) {
bytes = (int)strlcpy(bufp, (const char *)text, size); bytes = (int)str_strlcpy(bufp, (const char *)text, size);
if (wrptr(&bufp, &size, bytes) != 0) { if (wrptr(&bufp, &size, bytes) != 0) {
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
if (bufp - sbuffer >= 6) { if (bufp - sbuffer >= 6) {
@ -283,19 +283,19 @@ order *create_order(keyword_t kwd, const struct locale * lang,
case 's': case 's':
s = va_arg(marker, const char *); s = va_arg(marker, const char *);
assert(s); assert(s);
bytes = (int)strlcpy(bufp, s, size); bytes = (int)str_strlcpy(bufp, s, size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
break; break;
case 'd': case 'd':
i = va_arg(marker, int); i = va_arg(marker, int);
bytes = (int)strlcpy(bufp, itoa10(i), size); bytes = (int)str_strlcpy(bufp, itoa10(i), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
break; break;
case 'i': case 'i':
i = va_arg(marker, int); i = va_arg(marker, int);
bytes = (int)strlcpy(bufp, itoa36(i), size); bytes = (int)str_strlcpy(bufp, itoa36(i), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
break; break;
@ -516,7 +516,7 @@ char *write_order(const order * ord, const struct locale *lang, char *buffer, si
if (kwd == NOKEYWORD) { if (kwd == NOKEYWORD) {
order_data *od = odata_load(ord->id); order_data *od = odata_load(ord->id);
const char *text = OD_STRING(od); const char *text = OD_STRING(od);
if (text) strlcpy(buffer, (const char *)text, size); if (text) str_strlcpy(buffer, (const char *)text, size);
else buffer[0] = 0; else buffer[0] = 0;
odata_release(od); odata_release(od);
} }

View file

@ -540,11 +540,11 @@ const char *racename(const struct locale *loc, const unit * u, const race * rc)
size_t size = sizeof(lbuf) - 1; size_t size = sizeof(lbuf) - 1;
int ch, bytes; int ch, bytes;
bytes = (int)strlcpy(bufp, LOC(loc, mkname("prefix", prefix)), size); bytes = (int)str_strlcpy(bufp, LOC(loc, mkname("prefix", prefix)), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, LOC(loc, rc_name_s(rc, u->number != 1)), size); bytes = (int)str_strlcpy(bufp, LOC(loc, rc_name_s(rc, u->number != 1)), size);
assert(~bufp[0] & 0x80 || !"unicode/not implemented"); assert(~bufp[0] & 0x80 || !"unicode/not implemented");
ch = tolower(*(unsigned char *)bufp); ch = tolower(*(unsigned char *)bufp);
bufp[0] = (char)ch; bufp[0] = (char)ch;

View file

@ -118,7 +118,7 @@ const char *write_regionname(const region * r, const faction * f, char *buffer,
char *buf = (char *)buffer; char *buf = (char *)buffer;
const struct locale *lang = f ? f->locale : 0; const struct locale *lang = f ? f->locale : 0;
if (r == NULL) { if (r == NULL) {
strlcpy(buf, "(null)", size); str_strlcpy(buf, "(null)", size);
} }
else { else {
plane *pl = rplane(r); plane *pl = rplane(r);

View file

@ -2,10 +2,10 @@
#include <kernel/config.h> #include <kernel/config.h>
#include "keyword.h" #include "keyword.h"
#include <util/bsdstring.h>
#include <util/language.h> #include <util/language.h>
#include <util/umlaut.h> #include <util/umlaut.h>
#include <util/log.h> #include <util/log.h>
#include <util/strings.h>
#include <critbit.h> #include <critbit.h>
@ -21,7 +21,7 @@ const char * keyword(keyword_t kwd)
if (!result[0]) { if (!result[0]) {
strcpy(result, "keyword::"); strcpy(result, "keyword::");
} }
strlcpy(result + 9, keywords[kwd], sizeof(result) - 9); str_strlcpy(result + 9, keywords[kwd], sizeof(result) - 9);
return result; return result;
} }

View file

@ -1632,7 +1632,7 @@ static int rename_cmd(unit * u, order * ord, char **s, const char *s2)
/* TODO: Validate to make sure people don't have illegal characters in /* TODO: Validate to make sure people don't have illegal characters in
* names, phishing-style? () come to mind. */ * names, phishing-style? () come to mind. */
strlcpy(name, s2, sizeof(name)); str_strlcpy(name, s2, sizeof(name));
if (unicode_utf8_trim(name) != 0) { if (unicode_utf8_trim(name) != 0) {
log_info("trimming name: %s", s2); log_info("trimming name: %s", s2);
} }
@ -2176,7 +2176,7 @@ int password_cmd(unit * u, struct order *ord)
} }
if (!pwok) { if (!pwok) {
cmistake(u, ord, 283, MSG_EVENT); cmistake(u, ord, 283, MSG_EVENT);
strlcpy(pwbuf, itoa36(rng_int()), sizeof(pwbuf)); str_strlcpy(pwbuf, itoa36(rng_int()), sizeof(pwbuf));
} }
faction_setpassword(u->faction, password_encode(pwbuf, PASSWORD_DEFAULT)); faction_setpassword(u->faction, password_encode(pwbuf, PASSWORD_DEFAULT));
ADDMSG(&u->faction->msgs, msg_message("changepasswd", ADDMSG(&u->faction->msgs, msg_message("changepasswd",

View file

@ -66,6 +66,7 @@
#include <util/log.h> #include <util/log.h>
#include <util/rand.h> #include <util/rand.h>
#include <util/rng.h> #include <util/rng.h>
#include <util/strings.h>
#include <selist.h> #include <selist.h>
@ -517,7 +518,7 @@ static order *make_movement_order(unit * u, const region * target, int moves,
--size; --size;
} }
bytes = bytes =
(int)strlcpy(bufp, (int)str_strlcpy(bufp,
(const char *)LOC(u->faction->locale, directions[dir]), size); (const char *)LOC(u->faction->locale, directions[dir]), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();

View file

@ -1115,15 +1115,15 @@ static void cycle_route(order * ord, unit * u, int gereist)
* hier keine normale direction), muss jede PAUSE einzeln * hier keine normale direction), muss jede PAUSE einzeln
* herausgefiltert und explizit gesetzt werden */ * herausgefiltert und explizit gesetzt werden */
if (neworder != obuf) { if (neworder != obuf) {
obuf += strlcat(obuf, " ", sizeof(neworder) - (obuf - neworder)); obuf += str_strlcat(obuf, " ", sizeof(neworder) - (obuf - neworder));
} }
obuf += strlcat(obuf, LOC(lang, parameters[P_PAUSE]), sizeof(neworder) - (obuf - neworder)); obuf += str_strlcat(obuf, LOC(lang, parameters[P_PAUSE]), sizeof(neworder) - (obuf - neworder));
} }
else { else {
if (neworder != obuf) { if (neworder != obuf) {
obuf += strlcat(obuf, " ", sizeof(neworder) - (obuf - neworder)); obuf += str_strlcat(obuf, " ", sizeof(neworder) - (obuf - neworder));
} }
obuf += strlcat(obuf, LOC(lang, shortdirections[d]), sizeof(neworder) - (obuf - neworder)); obuf += str_strlcat(obuf, LOC(lang, shortdirections[d]), sizeof(neworder) - (obuf - neworder));
} }
} }

View file

@ -31,11 +31,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* util includes */ /* util includes */
#include <util/base36.h> #include <util/base36.h>
#include <util/bsdstring.h>
#include <util/functions.h> #include <util/functions.h>
#include <util/language.h> #include <util/language.h>
#include <util/macros.h> #include <util/macros.h>
#include <util/rng.h> #include <util/rng.h>
#include <util/strings.h>
#include <util/unicode.h> #include <util/unicode.h>
/* libc includes */ /* libc includes */
@ -102,22 +102,22 @@ static void make_name(unit *u, const char *monster, int *num_postfix,
sprintf(zText, "%s_prefix_%d", monster, uv); sprintf(zText, "%s_prefix_%d", monster, uv);
str = locale_getstring(default_locale, zText); str = locale_getstring(default_locale, zText);
if (str) { if (str) {
size_t sz = strlcpy(name, (const char *)str, sizeof(name)); size_t sz = str_strlcpy(name, (const char *)str, sizeof(name));
strlcpy(name + sz, " ", sizeof(name) - sz); str_strlcpy(name + sz, " ", sizeof(name) - sz);
} }
} }
sprintf(zText, "%s_name_%d", monster, uu); sprintf(zText, "%s_name_%d", monster, uu);
str = locale_getstring(default_locale, zText); str = locale_getstring(default_locale, zText);
if (str) if (str)
strlcat(name, (const char *)str, sizeof(name)); str_strlcat(name, (const char *)str, sizeof(name));
if (un < *num_postfix) { if (un < *num_postfix) {
sprintf(zText, "%s_postfix_%d", monster, un); sprintf(zText, "%s_postfix_%d", monster, un);
str = locale_getstring(default_locale, zText); str = locale_getstring(default_locale, zText);
if (str) { if (str) {
strlcat(name, " ", sizeof(name)); str_strlcat(name, " ", sizeof(name));
strlcat(name, (const char *)str, sizeof(name)); str_strlcat(name, (const char *)str, sizeof(name));
} }
} }
unit_setname(u, name); unit_setname(u, name);
@ -358,14 +358,14 @@ static void dracoid_name(unit * u)
mid_syllabels = rng_int() % 4; mid_syllabels = rng_int() % 4;
sz = strlcpy(name, drac_pre[rng_int() % DRAC_PRE], sizeof(name)); sz = str_strlcpy(name, drac_pre[rng_int() % DRAC_PRE], sizeof(name));
while (mid_syllabels > 0) { while (mid_syllabels > 0) {
mid_syllabels--; mid_syllabels--;
if (rng_int() % 10 < 4) if (rng_int() % 10 < 4)
strlcat(name, "'", sizeof(name)); str_strlcat(name, "'", sizeof(name));
sz += strlcat(name, drac_mid[rng_int() % DRAC_MID], sizeof(name)); sz += str_strlcat(name, drac_mid[rng_int() % DRAC_MID], sizeof(name));
} }
sz += strlcat(name, drac_suf[rng_int() % DRAC_SUF], sizeof(name)); sz += str_strlcat(name, drac_suf[rng_int() % DRAC_SUF], sizeof(name));
unit_setname(u, name); unit_setname(u, name);
} }

View file

@ -243,12 +243,12 @@ static size_t write_spell_modifier(const spell * sp, int flag, const char * str,
if (sp->sptyp & flag) { if (sp->sptyp & flag) {
size_t bytes = 0; size_t bytes = 0;
if (cont) { if (cont) {
bytes = strlcpy(bufp, ", ", size); bytes = str_strlcpy(bufp, ", ", size);
} }
else { else {
bytes = strlcpy(bufp, " ", size); bytes = str_strlcpy(bufp, " ", size);
} }
bytes += strlcpy(bufp + bytes, str, size - bytes); bytes += str_strlcpy(bufp + bytes, str, size - bytes);
return bytes; return bytes;
} }
return 0; return 0;
@ -264,10 +264,10 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc
const char *params = sp->parameter; const char *params = sp->parameter;
if (sp->sptyp & ISCOMBATSPELL) { if (sp->sptyp & ISCOMBATSPELL) {
bytes = (int)strlcpy(bufp, LOC(lang, keyword(K_COMBATSPELL)), size); bytes = (int)str_strlcpy(bufp, LOC(lang, keyword(K_COMBATSPELL)), size);
} }
else { else {
bytes = (int)strlcpy(bufp, LOC(lang, keyword(K_CAST)), size); bytes = (int)str_strlcpy(bufp, LOC(lang, keyword(K_CAST)), size);
} }
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
@ -334,12 +334,12 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
else if (cp == 'r') { else if (cp == 'r') {
bytes = (int)strlcpy(bufp, " <x> <y>", size); bytes = (int)str_strlcpy(bufp, " <x> <y>", size);
if (*params == '+') { if (*params == '+') {
++params; ++params;
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, " [<x> <y> ...]", size); bytes = (int)str_strlcpy(bufp, " [<x> <y> ...]", size);
} }
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
@ -372,7 +372,7 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc
++maxparam; ++maxparam;
} }
if (!maxparam || maxparam > 1) { if (!maxparam || maxparam > 1) {
bytes = (int)strlcpy(bufp, " (", size); bytes = (int)str_strlcpy(bufp, " (", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
@ -380,7 +380,7 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc
for (targetp = targets; targetp->flag; ++targetp) { for (targetp = targets; targetp->flag; ++targetp) {
if (!maxparam || sp->sptyp & targetp->flag) { if (!maxparam || sp->sptyp & targetp->flag) {
if (i++ != 0) { if (i++ != 0) {
bytes = (int)strlcpy(bufp, " |", size); bytes = (int)str_strlcpy(bufp, " |", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
@ -404,7 +404,7 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc
} }
} }
if (!maxparam || maxparam > 1) { if (!maxparam || maxparam > 1) {
bytes = (int)strlcpy(bufp, " )", size); bytes = (int)str_strlcpy(bufp, " )", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
@ -458,7 +458,7 @@ void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *la
paragraph(out, LOC(lang, "nr_spell_description"), 0, 0, 0); paragraph(out, LOC(lang, "nr_spell_description"), 0, 0, 0);
paragraph(out, spell_info(sp, lang), 2, 0, 0); paragraph(out, spell_info(sp, lang), 2, 0, 0);
bytes = (int)strlcpy(bufp, LOC(lang, "nr_spell_type"), size); bytes = (int)str_strlcpy(bufp, LOC(lang, "nr_spell_type"), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
@ -467,16 +467,16 @@ void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *la
--size; --size;
} }
if (sp->sptyp & PRECOMBATSPELL) { if (sp->sptyp & PRECOMBATSPELL) {
bytes = (int)strlcpy(bufp, LOC(lang, "sptype_precombat"), size); bytes = (int)str_strlcpy(bufp, LOC(lang, "sptype_precombat"), size);
} }
else if (sp->sptyp & COMBATSPELL) { else if (sp->sptyp & COMBATSPELL) {
bytes = (int)strlcpy(bufp, LOC(lang, "sptype_combat"), size); bytes = (int)str_strlcpy(bufp, LOC(lang, "sptype_combat"), size);
} }
else if (sp->sptyp & POSTCOMBATSPELL) { else if (sp->sptyp & POSTCOMBATSPELL) {
bytes = (int)strlcpy(bufp, LOC(lang, "sptype_postcombat"), size); bytes = (int)str_strlcpy(bufp, LOC(lang, "sptype_postcombat"), size);
} }
else { else {
bytes = (int)strlcpy(bufp, LOC(lang, "sptype_normal"), size); bytes = (int)str_strlcpy(bufp, LOC(lang, "sptype_normal"), size);
} }
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
@ -522,7 +522,7 @@ void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *la
size = sizeof(buf) - 1; size = sizeof(buf) - 1;
bufp = buf; bufp = buf;
bytes = (int)strlcpy(buf, LOC(lang, "nr_spell_modifiers"), size); bytes = (int)str_strlcpy(buf, LOC(lang, "nr_spell_modifiers"), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
@ -811,13 +811,13 @@ static void prices(struct stream *out, const region * r, const faction * f)
msg_release(m); msg_release(m);
if (n > 0) { if (n > 0) {
bytes = (int)strlcpy(bufp, " ", size); bytes = (int)str_strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_trade_intro"), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_trade_intro"), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, " ", size); bytes = (int)str_strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
@ -831,29 +831,29 @@ static void prices(struct stream *out, const region * r, const faction * f)
msg_release(m); msg_release(m);
n--; n--;
if (n == 0) { if (n == 0) {
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_trade_end"), bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_trade_end"),
size); size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
else if (n == 1) { else if (n == 1) {
bytes = (int)strlcpy(bufp, " ", size); bytes = (int)str_strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_trade_final"), bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_trade_final"),
size); size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, " ", size); bytes = (int)str_strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
else { else {
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_trade_next"), bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_trade_next"),
size); size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, " ", size); bytes = (int)str_strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
@ -967,12 +967,12 @@ void report_region(struct stream *out, const region * r, faction * f)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
/* Terrain */ /* Terrain */
bytes = (int)strlcpy(bufp, ", ", size); bytes = (int)str_strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
tname = terrain_name(r); tname = terrain_name(r);
bytes = (int)strlcpy(bufp, LOC(f->locale, tname), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, tname), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
@ -987,17 +987,17 @@ void report_region(struct stream *out, const region * r, faction * f)
if (fval(r, RF_MALLORN)) { if (fval(r, RF_MALLORN)) {
if (trees == 1) { if (trees == 1) {
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_mallorntree"), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_mallorntree"), size);
} }
else { else {
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_mallorntree_p"), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_mallorntree_p"), size);
} }
} }
else if (trees == 1) { else if (trees == 1) {
bytes = (int)strlcpy(bufp, LOC(f->locale, "tree"), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, "tree"), size);
} }
else { else {
bytes = (int)strlcpy(bufp, LOC(f->locale, "tree_p"), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, "tree_p"), size);
} }
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
@ -1034,16 +1034,16 @@ void report_region(struct stream *out, const region * r, faction * f)
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
bytes = (int)strlcpy(bufp, " ", size); bytes = (int)str_strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = bytes =
(int)strlcpy(bufp, LOC(f->locale, p == 1 ? "peasant" : "peasant_p"), (int)str_strlcpy(bufp, LOC(f->locale, p == 1 ? "peasant" : "peasant_p"),
size); size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
if (is_mourning(r, turn + 1)) { if (is_mourning(r, turn + 1)) {
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_mourning"), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_mourning"), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
@ -1053,7 +1053,7 @@ void report_region(struct stream *out, const region * r, faction * f)
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = bytes =
(int)strlcpy(bufp, LOC(f->locale, resourcename(get_resourcetype(R_SILVER), (int)str_strlcpy(bufp, LOC(f->locale, resourcename(get_resourcetype(R_SILVER),
rmoney(r) != 1)), size); rmoney(r) != 1)), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
@ -1065,26 +1065,26 @@ void report_region(struct stream *out, const region * r, faction * f)
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = bytes =
(int)strlcpy(bufp, LOC(f->locale, resourcename(get_resourcetype(R_HORSE), (int)str_strlcpy(bufp, LOC(f->locale, resourcename(get_resourcetype(R_HORSE),
(rhorses(r) > 1) ? GR_PLURAL : 0)), size); (rhorses(r) > 1) ? GR_PLURAL : 0)), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
bytes = (int)strlcpy(bufp, ".", size); bytes = (int)str_strlcpy(bufp, ".", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
if (r->land && r->land->display && r->land->display[0]) { if (r->land && r->land->display && r->land->display[0]) {
bytes = (int)strlcpy(bufp, " ", size); bytes = (int)str_strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, r->land->display, size); bytes = (int)str_strlcpy(bufp, r->land->display, size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
n = r->land->display[strlen(r->land->display) - 1]; n = r->land->display[strlen(r->land->display) - 1];
if (n != '!' && n != '?' && n != '.') { if (n != '!' && n != '?' && n != '.') {
bytes = (int)strlcpy(bufp, ".", size); bytes = (int)str_strlcpy(bufp, ".", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
@ -1095,7 +1095,7 @@ void report_region(struct stream *out, const region * r, faction * f)
message *msg; message *msg;
if (owner != NULL) { if (owner != NULL) {
bytes = (int)strlcpy(bufp, " ", size); bytes = (int)str_strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
msg = msg_message("nr_region_owner", "faction", owner); msg = msg_message("nr_region_owner", "faction", owner);
@ -1108,10 +1108,10 @@ void report_region(struct stream *out, const region * r, faction * f)
a = a_find(r->attribs, &at_overrideroads); a = a_find(r->attribs, &at_overrideroads);
if (a) { if (a) {
bytes = (int)strlcpy(bufp, " ", size); bytes = (int)str_strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, (char *)a->data.v, size); bytes = (int)str_strlcpy(bufp, (char *)a->data.v, size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
@ -1135,20 +1135,20 @@ void report_region(struct stream *out, const region * r, faction * f)
if (dh) { if (dh) {
char regname[4096]; char regname[4096];
if (nrd == 0) { if (nrd == 0) {
bytes = (int)strlcpy(bufp, " ", size); bytes = (int)str_strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_nb_final"), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_nb_final"), size);
} }
else { else {
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_nb_next"), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_nb_next"), size);
} }
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, LOC(f->locale, directions[d]), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, directions[d]), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, " ", size); bytes = (int)str_strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
f_regionid(r2, f, regname, sizeof(regname)); f_regionid(r2, f, regname, sizeof(regname));
@ -1157,7 +1157,7 @@ void report_region(struct stream *out, const region * r, faction * f)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
else { else {
bytes = (int)strlcpy(bufp, " ", size); bytes = (int)str_strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
MSG(("nr_vicinitystart", "dir region", d, r2), bufp, size, f->locale, MSG(("nr_vicinitystart", "dir region", d, r2), bufp, size, f->locale,
@ -1171,22 +1171,22 @@ void report_region(struct stream *out, const region * r, faction * f)
for (a = a_find(r->attribs, &at_direction); a && a->type == &at_direction; for (a = a_find(r->attribs, &at_direction); a && a->type == &at_direction;
a = a->next) { a = a->next) {
spec_direction *spd = (spec_direction *)(a->data.v); spec_direction *spd = (spec_direction *)(a->data.v);
bytes = (int)strlcpy(bufp, " ", size); bytes = (int)str_strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, LOC(f->locale, spd->desc), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, spd->desc), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, " (\"", size); bytes = (int)str_strlcpy(bufp, " (\"", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, LOC(f->locale, spd->keyword), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, spd->keyword), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, "\")", size); bytes = (int)str_strlcpy(bufp, "\")", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, ".", size); bytes = (int)str_strlcpy(bufp, ".", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
dh = 1; dh = 1;
@ -1206,7 +1206,7 @@ void report_region(struct stream *out, const region * r, faction * f)
size = sizeof(buf) - 1; size = sizeof(buf) - 1;
/* this localization might not work for every language but is fine for de and en */ /* this localization might not work for every language but is fine for de and en */
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_schemes_prefix"), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_schemes_prefix"), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
rl2 = rl; rl2 = rl;
@ -1216,12 +1216,12 @@ void report_region(struct stream *out, const region * r, faction * f)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
rl2 = rl2->next; rl2 = rl2->next;
if (rl2) { if (rl2) {
bytes = (int)strlcpy(bufp, ", ", size); bytes = (int)str_strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
} }
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_schemes_postfix"), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_schemes_postfix"), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
free_regionlist(rl); free_regionlist(rl);
@ -1249,14 +1249,14 @@ void report_region(struct stream *out, const region * r, faction * f)
continue; continue;
/* this localization might not work for every language but is fine for de and en */ /* this localization might not work for every language but is fine for de and en */
if (first) if (first)
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_borderlist_prefix"), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_borderlist_prefix"), size);
else if (e->lastd == d) else if (e->lastd == d)
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_borderlist_lastfix"), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_borderlist_lastfix"), size);
else else
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_borderlist_infix"), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_borderlist_infix"), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, LOC(f->locale, directions[d]), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, directions[d]), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
first = false; first = false;
@ -1473,10 +1473,10 @@ report_template(const char *filename, report_context * ctx, const char *bom)
if (!curse_active(get_curse(b->attribs, &ct_nocostbuilding))) { if (!curse_active(get_curse(b->attribs, &ct_nocostbuilding))) {
int cost = buildingmaintenance(b, rsilver); int cost = buildingmaintenance(b, rsilver);
if (cost > 0) { if (cost > 0) {
bytes = (int)strlcpy(bufp, ",U", size); bytes = (int)str_strlcpy(bufp, ",U", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, itoa10(cost), size); bytes = (int)str_strlcpy(bufp, itoa10(cost), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
@ -1484,23 +1484,23 @@ report_template(const char *filename, report_context * ctx, const char *bom)
} }
else if (u->ship) { else if (u->ship) {
if (ship_owner(u->ship) == u) { if (ship_owner(u->ship) == u) {
bytes = (int)strlcpy(bufp, ",S", size); bytes = (int)str_strlcpy(bufp, ",S", size);
} }
else { else {
bytes = (int)strlcpy(bufp, ",s", size); bytes = (int)str_strlcpy(bufp, ",s", size);
} }
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, itoa36(u->ship->no), size); bytes = (int)str_strlcpy(bufp, itoa36(u->ship->no), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
if (lifestyle(u) == 0) { if (lifestyle(u) == 0) {
bytes = (int)strlcpy(bufp, ",I", size); bytes = (int)str_strlcpy(bufp, ",I", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
bytes = (int)strlcpy(bufp, "]", size); bytes = (int)str_strlcpy(bufp, "]", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
@ -1533,7 +1533,7 @@ report_template(const char *filename, report_context * ctx, const char *bom)
} }
} }
newline(out); newline(out);
strlcpy(buf, LOC(lang, parameters[P_NEXT]), sizeof(buf)); str_strlcpy(buf, LOC(lang, parameters[P_NEXT]), sizeof(buf));
rps_nowrap(out, buf); rps_nowrap(out, buf);
newline(out); newline(out);
fstream_done(&strm); fstream_done(&strm);
@ -1564,24 +1564,24 @@ show_allies(const faction * f, const ally * allies, char *buf, size_t size)
i++; i++;
if (dh) { if (dh) {
if (i == allierte) { if (i == allierte) {
bytes = (int)strlcpy(bufp, LOC(f->locale, "list_and"), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, "list_and"), size);
} }
else { else {
bytes = (int)strlcpy(bufp, ", ", size); bytes = (int)str_strlcpy(bufp, ", ", size);
} }
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
dh = 1; dh = 1;
hh = 0; hh = 0;
bytes = (int)strlcpy(bufp, factionname(sf->faction), size); bytes = (int)str_strlcpy(bufp, factionname(sf->faction), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, " (", size); bytes = (int)str_strlcpy(bufp, " (", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
if ((mode & HELP_ALL) == HELP_ALL) { if ((mode & HELP_ALL) == HELP_ALL) {
bytes = (int)strlcpy(bufp, LOC(f->locale, parameters[P_ANY]), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, parameters[P_ANY]), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
@ -1612,22 +1612,22 @@ show_allies(const faction * f, const ally * allies, char *buf, size_t size)
} }
if (p != MAXPARAMS) { if (p != MAXPARAMS) {
if (hh) { if (hh) {
bytes = (int)strlcpy(bufp, ", ", size); bytes = (int)str_strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
bytes = (int)strlcpy(bufp, LOC(f->locale, parameters[p]), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, parameters[p]), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
hh = 1; hh = 1;
} }
} }
} }
bytes = (int)strlcpy(bufp, ")", size); bytes = (int)str_strlcpy(bufp, ")", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
bytes = (int)strlcpy(bufp, ".", size); bytes = (int)str_strlcpy(bufp, ".", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
*bufp = 0; *bufp = 0;
@ -1702,31 +1702,31 @@ static void guards(struct stream *out, const region * r, const faction * see)
size_t size = sizeof(buf) - 1; size_t size = sizeof(buf) - 1;
int bytes; int bytes;
bytes = (int)strlcpy(bufp, LOC(see->locale, "nr_guarding_prefix"), size); bytes = (int)str_strlcpy(bufp, LOC(see->locale, "nr_guarding_prefix"), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
for (i = 0; i != nextguard + (tarned ? 1 : 0); ++i) { for (i = 0; i != nextguard + (tarned ? 1 : 0); ++i) {
if (i != 0) { if (i != 0) {
if (i == nextguard - (tarned ? 0 : 1)) { if (i == nextguard - (tarned ? 0 : 1)) {
bytes = (int)strlcpy(bufp, LOC(see->locale, "list_and"), size); bytes = (int)str_strlcpy(bufp, LOC(see->locale, "list_and"), size);
} }
else { else {
bytes = (int)strlcpy(bufp, ", ", size); bytes = (int)str_strlcpy(bufp, ", ", size);
} }
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
if (i < nextguard) { if (i < nextguard) {
bytes = (int)strlcpy(bufp, factionname(guardians[i]), size); bytes = (int)str_strlcpy(bufp, factionname(guardians[i]), size);
} }
else { else {
bytes = (int)strlcpy(bufp, LOC(see->locale, "nr_guarding_unknown"), size); bytes = (int)str_strlcpy(bufp, LOC(see->locale, "nr_guarding_unknown"), size);
} }
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
bytes = (int)strlcpy(bufp, LOC(see->locale, "nr_guarding_postfix"), size); bytes = (int)str_strlcpy(bufp, LOC(see->locale, "nr_guarding_postfix"), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
newline(out); newline(out);
@ -1819,26 +1819,26 @@ nr_ship(struct stream *out, const region *r, const ship * sh, const faction * f,
} }
if (!fval(r->terrain, SEA_REGION)) { if (!fval(r->terrain, SEA_REGION)) {
if (sh->coast != NODIRECTION) { if (sh->coast != NODIRECTION) {
bytes = (int)strlcpy(bufp, ", ", size); bytes = (int)str_strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, LOC(f->locale, coasts[sh->coast]), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, coasts[sh->coast]), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
} }
ch = 0; ch = 0;
if (sh->display && sh->display[0]) { if (sh->display && sh->display[0]) {
bytes = (int)strlcpy(bufp, "; ", size); bytes = (int)str_strlcpy(bufp, "; ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, sh->display, size); bytes = (int)str_strlcpy(bufp, sh->display, size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
ch = sh->display[strlen(sh->display) - 1]; ch = sh->display[strlen(sh->display) - 1];
} }
if (ch != '!' && ch != '?' && ch != '.') { if (ch != '!' && ch != '?' && ch != '.') {
bytes = (int)strlcpy(bufp, ".", size); bytes = (int)str_strlcpy(bufp, ".", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
@ -1869,7 +1869,7 @@ nr_building(struct stream *out, const region *r, const building *b, const factio
report_building(b, &bname, &billusion); report_building(b, &bname, &billusion);
name = LOC(lang, billusion ? billusion : bname); name = LOC(lang, billusion ? billusion : bname);
bytes = (int)strlcpy(bufp, name, size); bytes = (int)str_strlcpy(bufp, name, size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
if (billusion) { if (billusion) {
@ -1884,7 +1884,7 @@ nr_building(struct stream *out, const region *r, const building *b, const factio
} }
if (!building_finished(b)) { if (!building_finished(b)) {
bytes = (int)strlcpy(bufp, LOC(lang, "nr_building_inprogress"), size); bytes = (int)str_strlcpy(bufp, LOC(lang, "nr_building_inprogress"), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
@ -1899,17 +1899,17 @@ nr_building(struct stream *out, const region *r, const building *b, const factio
} }
i = 0; i = 0;
if (b->display && b->display[0]) { if (b->display && b->display[0]) {
bytes = (int)strlcpy(bufp, "; ", size); bytes = (int)str_strlcpy(bufp, "; ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, b->display, size); bytes = (int)str_strlcpy(bufp, b->display, size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
i = b->display[strlen(b->display) - 1]; i = b->display[strlen(b->display) - 1];
} }
if (i != '!' && i != '?' && i != '.') { if (i != '!' && i != '?' && i != '.') {
bytes = (int)strlcpy(bufp, ".", size); bytes = (int)str_strlcpy(bufp, ".", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
@ -2028,7 +2028,7 @@ void report_travelthru(struct stream *out, region *r, const faction *f)
init_cb(&cbdata, out, buf, sizeof(buf), f); init_cb(&cbdata, out, buf, sizeof(buf), f);
cbdata.maxtravel = maxtravel; cbdata.maxtravel = maxtravel;
cbdata.writep += cbdata.writep +=
strlcpy(buf, LOC(f->locale, "travelthru_header"), sizeof(buf)); str_strlcpy(buf, LOC(f->locale, "travelthru_header"), sizeof(buf));
travelthru_map(r, cb_write_travelthru, &cbdata); travelthru_map(r, cb_write_travelthru, &cbdata);
return; return;
} }
@ -2165,10 +2165,10 @@ report_plaintext(const char *filename, report_context * ctx,
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
for (op = 0; op != MAXOPTIONS; op++) { for (op = 0; op != MAXOPTIONS; op++) {
if (f->options & want(op) && options[op]) { if (f->options & want(op) && options[op]) {
bytes = (int)strlcpy(bufp, " ", size); bytes = (int)str_strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, LOC(f->locale, options[op]), size); bytes = (int)str_strlcpy(bufp, LOC(f->locale, options[op]), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
@ -2227,12 +2227,12 @@ report_plaintext(const char *filename, report_context * ctx,
requirement *rm = ptype->itype->construction->materials; requirement *rm = ptype->itype->construction->materials;
while (rm->number) { while (rm->number) {
bytes = bytes =
(int)strlcpy(bufp, LOC(f->locale, resourcename(rm->rtype, 0)), size); (int)str_strlcpy(bufp, LOC(f->locale, resourcename(rm->rtype, 0)), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
++m; ++m;
if (rm->number) if (rm->number)
bytes = (int)strlcpy(bufp, ", ", size); bytes = (int)str_strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }

View file

@ -169,14 +169,14 @@ size_t report_status(const unit * u, const struct locale *lang, char *fsbuf, siz
struct locale *wloc = get_locale(lname); struct locale *wloc = get_locale(lname);
log_warning("no translation for combat status %s in %s", combatstatus[u->status], lname); log_warning("no translation for combat status %s in %s", combatstatus[u->status], lname);
locale_setstring(wloc, combatstatus[u->status], combatstatus[u->status] + 7); locale_setstring(wloc, combatstatus[u->status], combatstatus[u->status] + 7);
len = strlcpy(fsbuf, combatstatus[u->status] + 7, buflen); len = str_strlcpy(fsbuf, combatstatus[u->status] + 7, buflen);
} }
else { else {
len = strlcpy(fsbuf, status, buflen); len = str_strlcpy(fsbuf, status, buflen);
} }
if (fval(u, UFL_NOAID)) { if (fval(u, UFL_NOAID)) {
len += strlcat(fsbuf + len, ", ", buflen - len); len += str_strlcat(fsbuf + len, ", ", buflen - len);
len += strlcat(fsbuf + len, LOC(lang, "status_noaid"), buflen - len); len += str_strlcat(fsbuf + len, LOC(lang, "status_noaid"), buflen - len);
} }
return len; return len;
@ -689,7 +689,7 @@ bufunit(const faction * f, const unit * u, unsigned int indent, seen_mode mode,
header = 1; header = 1;
} }
else { else {
n = (int)strlcpy(bufp, ", ", size); n = (int)str_strlcpy(bufp, ", ", size);
} }
if (wrptr(&bufp, &size, n) != 0) { if (wrptr(&bufp, &size, n) != 0) {
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
@ -1609,9 +1609,9 @@ static void write_script(FILE * F, const faction * f)
for (rtype = report_types; rtype != NULL; rtype = rtype->next) { for (rtype = report_types; rtype != NULL; rtype = rtype->next) {
if (f->options & rtype->flag) { if (f->options & rtype->flag) {
if (buf[0]) { if (buf[0]) {
strlcat(buf, ",", sizeof(buf)); str_strlcat(buf, ",", sizeof(buf));
} }
strlcat(buf, rtype->extension, sizeof(buf)); str_strlcat(buf, rtype->extension, sizeof(buf));
} }
} }
fputs(buf, F); fputs(buf, F);
@ -1746,8 +1746,8 @@ const char *trailinto(const region * r, const struct locale *lang)
const char *tname = terrain_name(r); const char *tname = terrain_name(r);
size_t sz; size_t sz;
sz = strlcpy(ref, tname, sizeof(ref)); sz = str_strlcpy(ref, tname, sizeof(ref));
sz += strlcat(ref + sz, "_trail", sizeof(ref) - sz); sz += str_strlcat(ref + sz, "_trail", sizeof(ref) - sz);
s = LOC(lang, ref); s = LOC(lang, ref);
if (s && *s) { if (s && *s) {
if (strstr(s, "%s")) if (strstr(s, "%s"))
@ -1762,7 +1762,7 @@ f_regionid(const region * r, const faction * f, char *buffer, size_t size)
{ {
size_t len; size_t len;
if (!r) { if (!r) {
len = strlcpy(buffer, "(Chaos)", size); len = str_strlcpy(buffer, "(Chaos)", size);
} }
else { else {
plane *pl = rplane(r); plane *pl = rplane(r);
@ -1771,7 +1771,7 @@ f_regionid(const region * r, const faction * f, char *buffer, size_t size)
int named = (name && name[0]); int named = (name && name[0]);
pnormalize(&nx, &ny, pl); pnormalize(&nx, &ny, pl);
adjust_coordinates(f, &nx, &ny, pl); adjust_coordinates(f, &nx, &ny, pl);
len = strlcpy(buffer, rname(r, f ? f->locale : 0), size); len = str_strlcpy(buffer, rname(r, f ? f->locale : 0), size);
snprintf(buffer + len, size - len, " (%d,%d%s%s)", nx, ny, named ? "," : "", (named) ? name : ""); snprintf(buffer + len, size - len, " (%d,%d%s%s)", nx, ny, named ? "," : "", (named) ? name : "");
buffer[size - 1] = 0; buffer[size - 1] = 0;
len = strlen(buffer); len = strlen(buffer);

View file

@ -62,6 +62,7 @@
#include <util/assert.h> #include <util/assert.h>
#include <util/attrib.h> #include <util/attrib.h>
#include <util/base36.h> #include <util/base36.h>
#include <util/bsdstring.h>
#include <util/event.h> #include <util/event.h>
#include <util/gamedata.h> #include <util/gamedata.h>
#include <util/language.h> #include <util/language.h>
@ -74,7 +75,7 @@
#include <util/rand.h> #include <util/rand.h>
#include <util/log.h> #include <util/log.h>
#include <util/nrmessage.h> #include <util/nrmessage.h>
#include <util/bsdstring.h> #include <util/strings.h>
#include <util/variant.h> #include <util/variant.h>
#include <util/goodies.h> #include <util/goodies.h>
#include <util/resolve.h> #include <util/resolve.h>
@ -539,7 +540,7 @@ static int sp_summon_familiar(castorder * co)
const race *rc; const race *rc;
int sk; int sk;
int dh, dh1; int dh, dh1;
size_t bytes; int bytes;
message *msg; message *msg;
char zText[2048], *bufp = zText; char zText[2048], *bufp = zText;
size_t size = sizeof(zText) - 1; size_t size = sizeof(zText) - 1;
@ -597,23 +598,20 @@ static int sp_summon_familiar(castorder * co)
} }
else { else {
if (dh == 0) { if (dh == 0) {
bytes = bytes = (int) str_strlcpy(bufp, (const char *)LOC(mage->faction->locale,
strlcpy(bufp, (const char *)LOC(mage->faction->locale,
"list_and"), size); "list_and"), size);
} }
else { else {
bytes = strlcpy(bufp, (const char *)", ", size); bytes = (int)str_strlcpy(bufp, (const char *)", ", size);
} }
assert(bytes <= INT_MAX); assert(bytes >= 0);
if (wrptr(&bufp, &size, (int)bytes) != 0) BUFFER_STRCAT(bufp, size, bytes);
WARN_STATIC_BUFFER();
} }
bytes = bytes =
strlcpy(bufp, (const char *)skillname((skill_t)sk, mage->faction->locale), str_strlcpy(bufp, (const char *)skillname((skill_t)sk, mage->faction->locale),
size); size);
assert(bytes <= INT_MAX); assert(bytes <= INT_MAX);
if (wrptr(&bufp, &size, (int)bytes) != 0) BUFFER_STRCAT(bufp, size, (int)bytes);
WARN_STATIC_BUFFER();
} }
} }
ADDMSG(&mage->faction->msgs, msg_message("familiar_describe", ADDMSG(&mage->faction->msgs, msg_message("familiar_describe",

View file

@ -46,10 +46,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* util includes */ /* util includes */
#include <util/attrib.h> #include <util/attrib.h>
#include <util/base36.h> #include <util/base36.h>
#include <util/bsdstring.h>
#include <util/parser.h> #include <util/parser.h>
#include <util/rand.h> #include <util/rand.h>
#include <util/rng.h> #include <util/rng.h>
#include <util/strings.h>
/* libc includes */ /* libc includes */
#include <assert.h> #include <assert.h>
@ -101,12 +101,12 @@ void spy_message(int spy, const unit * u, const unit * target)
first = 0; first = 0;
} }
else { else {
strlcat(buf, ", ", sizeof(buf)); str_strlcat(buf, ", ", sizeof(buf));
} }
strlcat(buf, (const char *)skillname((skill_t)sv->id, u->faction->locale), str_strlcat(buf, (const char *)skillname((skill_t)sv->id, u->faction->locale),
sizeof(buf)); sizeof(buf));
strlcat(buf, " ", sizeof(buf)); str_strlcat(buf, " ", sizeof(buf));
strlcat(buf, itoa10(eff_skill(target, sv, target->region)), str_strlcat(buf, itoa10(eff_skill(target, sv, target->region)),
sizeof(buf)); sizeof(buf));
} }
} }

View file

@ -46,12 +46,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* util includes */ /* util includes */
#include <util/attrib.h> #include <util/attrib.h>
#include <util/base36.h> #include <util/base36.h>
#include <util/bsdstring.h>
#include <util/language.h> #include <util/language.h>
#include <util/log.h> #include <util/log.h>
#include <util/parser.h> #include <util/parser.h>
#include <util/rand.h> #include <util/rand.h>
#include <util/rng.h> #include <util/rng.h>
#include <util/strings.h>
#include <util/umlaut.h> #include <util/umlaut.h>
#include <selist.h> #include <selist.h>
@ -409,7 +409,7 @@ int teach_cmd(unit * teacher, struct order *ord)
strncat(zOrder, " ", sz - 1); strncat(zOrder, " ", sz - 1);
--sz; --sz;
} }
sz -= strlcpy(zOrder + 4096 - sz, itoa36(student->no), sz); sz -= str_strlcpy(zOrder + 4096 - sz, itoa36(student->no), sz);
if (getkeyword(student->thisorder) != K_STUDY) { if (getkeyword(student->thisorder) != K_STUDY) {
ADDMSG(&teacher->faction->msgs, ADDMSG(&teacher->faction->msgs,

View file

@ -6,7 +6,8 @@
int wrptr(char **ptr, size_t * size, int bytes); int wrptr(char **ptr, size_t * size, int bytes);
char * strlcpy_w(char *dst, const char *src, size_t *siz, const char *err, const char *file, int line); char * strlcpy_w(char *dst, const char *src, size_t *siz, const char *err, const char *file, int line);
#define WARN_STATIC_BUFFER_EX(foo) log_warning("%s: static buffer too small in %s:%d\n", (foo), __FILE__, __LINE__) #define BUFFER_STRCAT(bufp, size, bytes) if (wrptr(&bufp, &size, bytes) != 0) log_warning("static buffer too small in %s:%d\n", __FILE__, __LINE__);
#define WARN_STATIC_BUFFER() log_warning("static buffer too small in %s:%d\n", __FILE__, __LINE__) #define WARN_STATIC_BUFFER() log_warning("static buffer too small in %s:%d\n", __FILE__, __LINE__)
#define INFO_STATIC_BUFFER() log_info("static buffer too small in %s:%d\n", __FILE__, __LINE__) #define INFO_STATIC_BUFFER() log_info("static buffer too small in %s:%d\n", __FILE__, __LINE__)
#define STRLCPY(dst, src, siz) strlcpy_w((dst), (src), &(siz), 0, __FILE__, __LINE__) #define STRLCPY(dst, src, siz) strlcpy_w((dst), (src), &(siz), 0, __FILE__, __LINE__)

View file

@ -6,49 +6,8 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
static void test_strlcat(CuTest * tc)
{
char buffer[32];
memset(buffer, 0x7f, sizeof(buffer));
buffer[0] = '\0';
CuAssertIntEquals(tc, 4, (int)strlcat(buffer, "herp", 4));
CuAssertStrEquals(tc, "her", buffer);
buffer[0] = '\0';
CuAssertIntEquals(tc, 4, (int)strlcat(buffer, "herp", 8));
CuAssertStrEquals(tc, "herp", buffer);
CuAssertIntEquals(tc, 0x7f, buffer[5]);
CuAssertIntEquals(tc, 8, (int)strlcat(buffer, "derp", 8));
CuAssertStrEquals(tc, "herpder", buffer);
CuAssertIntEquals(tc, 0x7f, buffer[8]);
}
static void test_strlcpy(CuTest * tc)
{
char buffer[32];
memset(buffer, 0x7f, sizeof(buffer));
CuAssertIntEquals(tc, 4, (int)strlcpy(buffer, "herp", 4));
CuAssertStrEquals(tc, "her", buffer);
CuAssertIntEquals(tc, 4, (int)strlcpy(buffer, "herp", 8)); /*-V666 */
CuAssertStrEquals(tc, "herp", buffer);
CuAssertIntEquals(tc, 0x7f, buffer[5]);
CuAssertIntEquals(tc, 8, (int)strlcpy(buffer, "herpderp", 8));
CuAssertStrEquals(tc, "herpder", buffer);
CuAssertIntEquals(tc, 0x7f, buffer[8]);
errno = 0;
}
CuSuite *get_bsdstring_suite(void) CuSuite *get_bsdstring_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_strlcat);
SUITE_ADD_TEST(suite, test_strlcpy);
return suite; return suite;
} }

View file

@ -12,8 +12,8 @@ without prior permission by the authors of Eressea.
#include <platform.h> #include <platform.h>
#include "log.h" #include "log.h"
#include "bsdstring.h"
#include "unicode.h" #include "unicode.h"
#include "strings.h"
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
@ -150,7 +150,7 @@ static int check_dupe(const char *format, int level)
} }
dupes = 0; dupes = 0;
} }
strlcpy(last_message, format, sizeof(last_message)); str_strlcpy(last_message, format, sizeof(last_message));
last_type = level; last_type = level;
return 0; return 0;
} }

View file

@ -135,7 +135,7 @@ const char *string, int level, const char *section)
for (i = 0; i != mtype->nparameters; ++i) { for (i = 0; i != mtype->nparameters; ++i) {
if (i != 0) if (i != 0)
*c++ = ' '; *c++ = ' ';
c += strlcpy(c, mtype->pnames[i], sizeof(zNames)-(c-zNames)); c += str_strlcpy(c, mtype->pnames[i], sizeof(zNames)-(c-zNames));
} }
nrt->vars = str_strdup(zNames); nrt->vars = str_strdup(zNames);
} }
@ -151,7 +151,7 @@ size_t size, const void *userdata)
const char *m = const char *m =
translate(nrt->string, userdata, nrt->vars, msg->parameters); translate(nrt->string, userdata, nrt->vars, msg->parameters);
if (m) { if (m) {
return strlcpy((char *)buffer, m, size); return str_strlcpy((char *)buffer, m, size);
} }
else { else {
log_error("Couldn't render message %s\n", nrt->mtype->name); log_error("Couldn't render message %s\n", nrt->mtype->name);

View file

@ -3,7 +3,7 @@
#endif #endif
#include "path.h" #include "path.h"
#include "bsdstring.h" #include "strings.h"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
@ -16,11 +16,11 @@ char * path_join(const char *p1, const char *p2, char *dst, size_t len) {
sz = strlen(p1); sz = strlen(p1);
} }
else { else {
sz = strlcpy(dst, p1, len); sz = str_strlcpy(dst, p1, len);
} }
assert(sz < len); assert(sz < len);
dst[sz++] = PATH_DELIM; dst[sz++] = PATH_DELIM;
strlcpy(dst + sz, p2, len - sz); str_strlcpy(dst + sz, p2, len - sz);
return dst; return dst;
} }

View file

@ -50,6 +50,45 @@ static void test_str_slprintf(CuTest * tc)
CuAssertIntEquals(tc, 0x7f, buffer[8]); CuAssertIntEquals(tc, 0x7f, buffer[8]);
} }
static void test_str_strlcat(CuTest * tc)
{
char buffer[32];
memset(buffer, 0x7f, sizeof(buffer));
buffer[0] = '\0';
CuAssertIntEquals(tc, 4, (int)str_strlcat(buffer, "herp", 4));
CuAssertStrEquals(tc, "her", buffer);
buffer[0] = '\0';
CuAssertIntEquals(tc, 4, (int)str_strlcat(buffer, "herp", 8));
CuAssertStrEquals(tc, "herp", buffer);
CuAssertIntEquals(tc, 0x7f, buffer[5]);
CuAssertIntEquals(tc, 8, (int)str_strlcat(buffer, "derp", 8));
CuAssertStrEquals(tc, "herpder", buffer);
CuAssertIntEquals(tc, 0x7f, buffer[8]);
}
static void test_str_strlcpy(CuTest * tc)
{
char buffer[32];
memset(buffer, 0x7f, sizeof(buffer));
CuAssertIntEquals(tc, 4, (int)str_strlcpy(buffer, "herp", 4));
CuAssertStrEquals(tc, "her", buffer);
CuAssertIntEquals(tc, 4, (int)str_strlcpy(buffer, "herp", 8)); /*-V666 */
CuAssertStrEquals(tc, "herp", buffer);
CuAssertIntEquals(tc, 0x7f, buffer[5]);
CuAssertIntEquals(tc, 8, (int)str_strlcpy(buffer, "herpderp", 8));
CuAssertStrEquals(tc, "herpder", buffer);
CuAssertIntEquals(tc, 0x7f, buffer[8]);
errno = 0;
}
CuSuite *get_strings_suite(void) CuSuite *get_strings_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
@ -57,5 +96,7 @@ CuSuite *get_strings_suite(void)
SUITE_ADD_TEST(suite, test_str_escape); SUITE_ADD_TEST(suite, test_str_escape);
SUITE_ADD_TEST(suite, test_str_replace); SUITE_ADD_TEST(suite, test_str_replace);
SUITE_ADD_TEST(suite, test_str_slprintf); SUITE_ADD_TEST(suite, test_str_slprintf);
SUITE_ADD_TEST(suite, test_str_strlcat);
SUITE_ADD_TEST(suite, test_str_strlcpy);
return suite; return suite;
} }

View file

@ -15,7 +15,7 @@
#include "translation.h" #include "translation.h"
#include "bsdstring.h" #include "strings.h"
#include "critbit.h" #include "critbit.h"
#include "log.h" #include "log.h"
#include "macros.h" #include "macros.h"
@ -291,7 +291,7 @@ static const char *parse_string(opstack ** stack, const char *in,
if (ic == NULL) if (ic == NULL)
return NULL; return NULL;
c = (char *)opop_v(stack); c = (char *)opop_v(stack);
bytes = (c ? strlcpy(oc, c, size) : 0); bytes = (c ? str_strlcpy(oc, c, size) : 0);
if (bytes < size) if (bytes < size)
oc += bytes; oc += bytes;
else else

View file

@ -21,7 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "assert.h" #include "assert.h"
#include "log.h" #include "log.h"
#include "bsdstring.h" #include "strings.h"
#include "unicode.h" #include "unicode.h"
#include <ctype.h> #include <ctype.h>
@ -212,7 +212,7 @@ void addtoken(tnode ** root, const char *str, variant id)
if (lcs == replace[i].ucs) { if (lcs == replace[i].ucs) {
char zText[1024]; char zText[1024];
memcpy(zText, replace[i].str, 3); memcpy(zText, replace[i].str, 3);
strlcpy(zText + 2, (const char *)str + len, sizeof(zText)-2); str_strlcpy(zText + 2, (const char *)str + len, sizeof(zText)-2);
addtoken(root, zText, id); addtoken(root, zText, id);
break; break;
} }