From a8140f1dc9244f45414dddd5ff90a4181cb56a62 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 30 Dec 2017 19:49:21 +0100 Subject: [PATCH] rename strlcpy->str_strlcpy, etc. --- src/battle.c | 8 +- src/bind_config.c | 5 +- src/kernel/config.c | 2 +- src/kernel/order.c | 12 +-- src/kernel/race.c | 4 +- src/kernel/region.c | 2 +- src/keyword.c | 4 +- src/laws.c | 4 +- src/monsters.c | 3 +- src/move.c | 8 +- src/names.c | 20 ++-- src/report.c | 200 +++++++++++++++++++------------------- src/reports.c | 22 ++--- src/spells.c | 20 ++-- src/spy.c | 10 +- src/study.c | 4 +- src/util/bsdstring.h | 3 +- src/util/bsdstring.test.c | 41 -------- src/util/log.c | 4 +- src/util/nrmessage.c | 4 +- src/util/path.c | 6 +- src/util/strings.test.c | 41 ++++++++ src/util/translation.c | 4 +- src/util/umlaut.c | 4 +- 24 files changed, 218 insertions(+), 217 deletions(-) diff --git a/src/battle.c b/src/battle.c index 63e2198f9..837d4a280 100644 --- a/src/battle.c +++ b/src/battle.c @@ -192,7 +192,7 @@ static char *sidename(side * s) static char sidename_buf[4][SIDENAMEBUFLEN]; /* STATIC_RESULT: used for return, not across calls */ 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++]; } @@ -202,7 +202,7 @@ static const char *sideabkz(side * s, bool truename) const faction *f = (s->stealthfaction && !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; } @@ -2896,10 +2896,10 @@ static void print_header(battle * b) for (df = s->fighters; df; df = df->next) { if (is_attacker(df)) { if (first) { - strlcpy(bufp, ", ", size); + str_strlcpy(bufp, ", ", size); } if (lastf) { - strlcpy(bufp, lastf, size); + str_strlcpy(bufp, lastf, size); first = true; } if (seematrix(f, s)) diff --git a/src/bind_config.c b/src/bind_config.c index 812b74df3..871d53dce 100644 --- a/src/bind_config.c +++ b/src/bind_config.c @@ -6,11 +6,12 @@ #include #include -#include + #include #include #include #include +#include #include @@ -53,7 +54,7 @@ int config_parse(const char *json) if (xp >= ep) break; } xp = (ep > json + 10) ? ep - 10 : json; - strlcpy(buffer, xp, sizeof(buffer)); + str_strlcpy(buffer, xp, sizeof(buffer)); buffer[9] = 0; log_error("json parse error in line %d, position %d, near `%s`\n", line, ep - lp, buffer); } diff --git a/src/kernel/config.c b/src/kernel/config.c index da0dd2e0f..89c3364cf 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -530,7 +530,7 @@ static const char * relpath(char *buf, size_t sz, const char *path) { path_join(g_basedir, path, buf, sz); } else { - strlcpy(buf, path, sz); + str_strlcpy(buf, path, sz); } return buf; } diff --git a/src/kernel/order.c b/src/kernel/order.c index 605f44be9..05a4ac4ba 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -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)); assert(str); if (text) --size; - bytes = (int)strlcpy(bufp, str, size); + bytes = (int)str_strlcpy(bufp, str, size); if (wrptr(&bufp, &size, bytes) != 0) { WARN_STATIC_BUFFER(); } @@ -117,7 +117,7 @@ char* get_command(const order *ord, const struct locale *lang, char *sbuffer, si } } 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) { WARN_STATIC_BUFFER(); if (bufp - sbuffer >= 6) { @@ -283,19 +283,19 @@ order *create_order(keyword_t kwd, const struct locale * lang, case 's': s = va_arg(marker, const char *); assert(s); - bytes = (int)strlcpy(bufp, s, size); + bytes = (int)str_strlcpy(bufp, s, size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); break; case 'd': 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) WARN_STATIC_BUFFER(); break; case 'i': 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) WARN_STATIC_BUFFER(); break; @@ -516,7 +516,7 @@ char *write_order(const order * ord, const struct locale *lang, char *buffer, si if (kwd == NOKEYWORD) { order_data *od = odata_load(ord->id); 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; odata_release(od); } diff --git a/src/kernel/race.c b/src/kernel/race.c index 6e7b12591..dd0649afb 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -540,11 +540,11 @@ const char *racename(const struct locale *loc, const unit * u, const race * rc) size_t size = sizeof(lbuf) - 1; 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) 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"); ch = tolower(*(unsigned char *)bufp); bufp[0] = (char)ch; diff --git a/src/kernel/region.c b/src/kernel/region.c index f0c0d0dbb..938e87bb1 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -118,7 +118,7 @@ const char *write_regionname(const region * r, const faction * f, char *buffer, char *buf = (char *)buffer; const struct locale *lang = f ? f->locale : 0; if (r == NULL) { - strlcpy(buf, "(null)", size); + str_strlcpy(buf, "(null)", size); } else { plane *pl = rplane(r); diff --git a/src/keyword.c b/src/keyword.c index a38c91e07..7519b6449 100644 --- a/src/keyword.c +++ b/src/keyword.c @@ -2,10 +2,10 @@ #include #include "keyword.h" -#include #include #include #include +#include #include @@ -21,7 +21,7 @@ const char * keyword(keyword_t kwd) if (!result[0]) { strcpy(result, "keyword::"); } - strlcpy(result + 9, keywords[kwd], sizeof(result) - 9); + str_strlcpy(result + 9, keywords[kwd], sizeof(result) - 9); return result; } diff --git a/src/laws.c b/src/laws.c index dbdf8efac..dd61c2572 100644 --- a/src/laws.c +++ b/src/laws.c @@ -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 * names, phishing-style? () come to mind. */ - strlcpy(name, s2, sizeof(name)); + str_strlcpy(name, s2, sizeof(name)); if (unicode_utf8_trim(name) != 0) { log_info("trimming name: %s", s2); } @@ -2176,7 +2176,7 @@ int password_cmd(unit * u, struct order *ord) } if (!pwok) { 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)); ADDMSG(&u->faction->msgs, msg_message("changepasswd", diff --git a/src/monsters.c b/src/monsters.c index 01ebbe8cd..9260f76ac 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -66,6 +66,7 @@ #include #include #include +#include #include @@ -517,7 +518,7 @@ static order *make_movement_order(unit * u, const region * target, int moves, --size; } bytes = - (int)strlcpy(bufp, + (int)str_strlcpy(bufp, (const char *)LOC(u->faction->locale, directions[dir]), size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); diff --git a/src/move.c b/src/move.c index 0932c7d4f..afee7399f 100644 --- a/src/move.c +++ b/src/move.c @@ -1115,15 +1115,15 @@ static void cycle_route(order * ord, unit * u, int gereist) * hier keine normale direction), muss jede PAUSE einzeln * herausgefiltert und explizit gesetzt werden */ 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 { 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)); } } diff --git a/src/names.c b/src/names.c index e58feceec..d8abc077b 100644 --- a/src/names.c +++ b/src/names.c @@ -31,11 +31,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include -#include #include #include #include #include +#include #include /* 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); str = locale_getstring(default_locale, zText); if (str) { - size_t sz = strlcpy(name, (const char *)str, sizeof(name)); - strlcpy(name + sz, " ", sizeof(name) - sz); + size_t sz = str_strlcpy(name, (const char *)str, sizeof(name)); + str_strlcpy(name + sz, " ", sizeof(name) - sz); } } sprintf(zText, "%s_name_%d", monster, uu); str = locale_getstring(default_locale, zText); if (str) - strlcat(name, (const char *)str, sizeof(name)); + str_strlcat(name, (const char *)str, sizeof(name)); if (un < *num_postfix) { sprintf(zText, "%s_postfix_%d", monster, un); str = locale_getstring(default_locale, zText); if (str) { - strlcat(name, " ", sizeof(name)); - strlcat(name, (const char *)str, sizeof(name)); + str_strlcat(name, " ", sizeof(name)); + str_strlcat(name, (const char *)str, sizeof(name)); } } unit_setname(u, name); @@ -358,14 +358,14 @@ static void dracoid_name(unit * u) 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) { mid_syllabels--; if (rng_int() % 10 < 4) - strlcat(name, "'", sizeof(name)); - sz += strlcat(name, drac_mid[rng_int() % DRAC_MID], sizeof(name)); + str_strlcat(name, "'", 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); } diff --git a/src/report.c b/src/report.c index 12506f2be..c431f1b1b 100644 --- a/src/report.c +++ b/src/report.c @@ -243,12 +243,12 @@ static size_t write_spell_modifier(const spell * sp, int flag, const char * str, if (sp->sptyp & flag) { size_t bytes = 0; if (cont) { - bytes = strlcpy(bufp, ", ", size); + bytes = str_strlcpy(bufp, ", ", size); } 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 0; @@ -264,10 +264,10 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc const char *params = sp->parameter; 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 { - 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) WARN_STATIC_BUFFER(); @@ -334,12 +334,12 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc WARN_STATIC_BUFFER(); } else if (cp == 'r') { - bytes = (int)strlcpy(bufp, " ", size); + bytes = (int)str_strlcpy(bufp, " ", size); if (*params == '+') { ++params; if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)strlcpy(bufp, " [ ...]", size); + bytes = (int)str_strlcpy(bufp, " [ ...]", size); } if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -372,7 +372,7 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc ++maxparam; } if (!maxparam || maxparam > 1) { - bytes = (int)strlcpy(bufp, " (", size); + bytes = (int)str_strlcpy(bufp, " (", size); if (wrptr(&bufp, &size, bytes) != 0) 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) { if (!maxparam || sp->sptyp & targetp->flag) { if (i++ != 0) { - bytes = (int)strlcpy(bufp, " |", size); + bytes = (int)str_strlcpy(bufp, " |", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -404,7 +404,7 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc } } if (!maxparam || maxparam > 1) { - bytes = (int)strlcpy(bufp, " )", size); + bytes = (int)str_strlcpy(bufp, " )", size); if (wrptr(&bufp, &size, bytes) != 0) 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, 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) WARN_STATIC_BUFFER(); @@ -467,16 +467,16 @@ void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *la --size; } 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) { - bytes = (int)strlcpy(bufp, LOC(lang, "sptype_combat"), size); + bytes = (int)str_strlcpy(bufp, LOC(lang, "sptype_combat"), size); } 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 { - 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) WARN_STATIC_BUFFER(); @@ -522,7 +522,7 @@ void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *la size = sizeof(buf) - 1; 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) WARN_STATIC_BUFFER(); @@ -811,13 +811,13 @@ static void prices(struct stream *out, const region * r, const faction * f) msg_release(m); if (n > 0) { - bytes = (int)strlcpy(bufp, " ", size); + bytes = (int)str_strlcpy(bufp, " ", size); if (wrptr(&bufp, &size, bytes) != 0) 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) WARN_STATIC_BUFFER(); - bytes = (int)strlcpy(bufp, " ", size); + bytes = (int)str_strlcpy(bufp, " ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -831,29 +831,29 @@ static void prices(struct stream *out, const region * r, const faction * f) msg_release(m); n--; 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); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } else if (n == 1) { - bytes = (int)strlcpy(bufp, " ", size); + bytes = (int)str_strlcpy(bufp, " ", size); if (wrptr(&bufp, &size, bytes) != 0) 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); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)strlcpy(bufp, " ", size); + bytes = (int)str_strlcpy(bufp, " ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } else { - bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_trade_next"), + bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_trade_next"), size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)strlcpy(bufp, " ", size); + bytes = (int)str_strlcpy(bufp, " ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -967,12 +967,12 @@ void report_region(struct stream *out, const region * r, faction * f) WARN_STATIC_BUFFER(); /* Terrain */ - bytes = (int)strlcpy(bufp, ", ", size); + bytes = (int)str_strlcpy(bufp, ", ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); 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) WARN_STATIC_BUFFER(); @@ -987,17 +987,17 @@ void report_region(struct stream *out, const region * r, faction * f) if (fval(r, RF_MALLORN)) { 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 { - 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) { - bytes = (int)strlcpy(bufp, LOC(f->locale, "tree"), size); + bytes = (int)str_strlcpy(bufp, LOC(f->locale, "tree"), size); } 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) WARN_STATIC_BUFFER(); @@ -1034,16 +1034,16 @@ void report_region(struct stream *out, const region * r, faction * f) if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } - bytes = (int)strlcpy(bufp, " ", size); + bytes = (int)str_strlcpy(bufp, " ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); 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); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); 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) WARN_STATIC_BUFFER(); } @@ -1053,7 +1053,7 @@ void report_region(struct stream *out, const region * r, faction * f) if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); 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); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -1065,26 +1065,26 @@ void report_region(struct stream *out, const region * r, faction * f) if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); 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); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } - bytes = (int)strlcpy(bufp, ".", size); + bytes = (int)str_strlcpy(bufp, ".", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); 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) 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) WARN_STATIC_BUFFER(); n = r->land->display[strlen(r->land->display) - 1]; if (n != '!' && n != '?' && n != '.') { - bytes = (int)strlcpy(bufp, ".", size); + bytes = (int)str_strlcpy(bufp, ".", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -1095,7 +1095,7 @@ void report_region(struct stream *out, const region * r, faction * f) message *msg; if (owner != NULL) { - bytes = (int)strlcpy(bufp, " ", size); + bytes = (int)str_strlcpy(bufp, " ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); 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); if (a) { - bytes = (int)strlcpy(bufp, " ", size); + bytes = (int)str_strlcpy(bufp, " ", size); if (wrptr(&bufp, &size, bytes) != 0) 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) WARN_STATIC_BUFFER(); } @@ -1135,20 +1135,20 @@ void report_region(struct stream *out, const region * r, faction * f) if (dh) { char regname[4096]; if (nrd == 0) { - bytes = (int)strlcpy(bufp, " ", size); + bytes = (int)str_strlcpy(bufp, " ", size); if (wrptr(&bufp, &size, bytes) != 0) 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 { - 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) 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) WARN_STATIC_BUFFER(); - bytes = (int)strlcpy(bufp, " ", size); + bytes = (int)str_strlcpy(bufp, " ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); 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(); } else { - bytes = (int)strlcpy(bufp, " ", size); + bytes = (int)str_strlcpy(bufp, " ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); 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; a = a->next) { 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) 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) WARN_STATIC_BUFFER(); - bytes = (int)strlcpy(bufp, " (\"", size); + bytes = (int)str_strlcpy(bufp, " (\"", size); if (wrptr(&bufp, &size, bytes) != 0) 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) WARN_STATIC_BUFFER(); - bytes = (int)strlcpy(bufp, "\")", size); + bytes = (int)str_strlcpy(bufp, "\")", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)strlcpy(bufp, ".", size); + bytes = (int)str_strlcpy(bufp, ".", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); dh = 1; @@ -1206,7 +1206,7 @@ void report_region(struct stream *out, const region * r, faction * f) size = sizeof(buf) - 1; /* 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) WARN_STATIC_BUFFER(); rl2 = rl; @@ -1216,12 +1216,12 @@ void report_region(struct stream *out, const region * r, faction * f) WARN_STATIC_BUFFER(); rl2 = rl2->next; if (rl2) { - bytes = (int)strlcpy(bufp, ", ", size); + bytes = (int)str_strlcpy(bufp, ", ", size); if (wrptr(&bufp, &size, bytes) != 0) 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) WARN_STATIC_BUFFER(); free_regionlist(rl); @@ -1249,14 +1249,14 @@ void report_region(struct stream *out, const region * r, faction * f) continue; /* this localization might not work for every language but is fine for de and en */ 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) - bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_borderlist_lastfix"), size); + bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_borderlist_lastfix"), size); 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) 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) WARN_STATIC_BUFFER(); 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))) { int cost = buildingmaintenance(b, rsilver); if (cost > 0) { - bytes = (int)strlcpy(bufp, ",U", size); + bytes = (int)str_strlcpy(bufp, ",U", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)strlcpy(bufp, itoa10(cost), size); + bytes = (int)str_strlcpy(bufp, itoa10(cost), size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -1484,23 +1484,23 @@ report_template(const char *filename, report_context * ctx, const char *bom) } else if (u->ship) { if (ship_owner(u->ship) == u) { - bytes = (int)strlcpy(bufp, ",S", size); + bytes = (int)str_strlcpy(bufp, ",S", size); } else { - bytes = (int)strlcpy(bufp, ",s", size); + bytes = (int)str_strlcpy(bufp, ",s", size); } if (wrptr(&bufp, &size, bytes) != 0) 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) WARN_STATIC_BUFFER(); } if (lifestyle(u) == 0) { - bytes = (int)strlcpy(bufp, ",I", size); + bytes = (int)str_strlcpy(bufp, ",I", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } - bytes = (int)strlcpy(bufp, "]", size); + bytes = (int)str_strlcpy(bufp, "]", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -1533,7 +1533,7 @@ report_template(const char *filename, report_context * ctx, const char *bom) } } 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); newline(out); fstream_done(&strm); @@ -1564,24 +1564,24 @@ show_allies(const faction * f, const ally * allies, char *buf, size_t size) i++; if (dh) { 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 { - bytes = (int)strlcpy(bufp, ", ", size); + bytes = (int)str_strlcpy(bufp, ", ", size); } if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } dh = 1; 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) WARN_STATIC_BUFFER(); - bytes = (int)strlcpy(bufp, " (", size); + bytes = (int)str_strlcpy(bufp, " (", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); 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) WARN_STATIC_BUFFER(); } @@ -1612,22 +1612,22 @@ show_allies(const faction * f, const ally * allies, char *buf, size_t size) } if (p != MAXPARAMS) { if (hh) { - bytes = (int)strlcpy(bufp, ", ", size); + bytes = (int)str_strlcpy(bufp, ", ", size); if (wrptr(&bufp, &size, bytes) != 0) 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) WARN_STATIC_BUFFER(); hh = 1; } } } - bytes = (int)strlcpy(bufp, ")", size); + bytes = (int)str_strlcpy(bufp, ")", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } - bytes = (int)strlcpy(bufp, ".", size); + bytes = (int)str_strlcpy(bufp, ".", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); *bufp = 0; @@ -1702,31 +1702,31 @@ static void guards(struct stream *out, const region * r, const faction * see) size_t size = sizeof(buf) - 1; 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) WARN_STATIC_BUFFER(); for (i = 0; i != nextguard + (tarned ? 1 : 0); ++i) { if (i != 0) { 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 { - bytes = (int)strlcpy(bufp, ", ", size); + bytes = (int)str_strlcpy(bufp, ", ", size); } if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } if (i < nextguard) { - bytes = (int)strlcpy(bufp, factionname(guardians[i]), size); + bytes = (int)str_strlcpy(bufp, factionname(guardians[i]), size); } 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) 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) WARN_STATIC_BUFFER(); 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 (sh->coast != NODIRECTION) { - bytes = (int)strlcpy(bufp, ", ", size); + bytes = (int)str_strlcpy(bufp, ", ", size); if (wrptr(&bufp, &size, bytes) != 0) 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) WARN_STATIC_BUFFER(); } } ch = 0; if (sh->display && sh->display[0]) { - bytes = (int)strlcpy(bufp, "; ", size); + bytes = (int)str_strlcpy(bufp, "; ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)strlcpy(bufp, sh->display, size); + bytes = (int)str_strlcpy(bufp, sh->display, size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); ch = sh->display[strlen(sh->display) - 1]; } if (ch != '!' && ch != '?' && ch != '.') { - bytes = (int)strlcpy(bufp, ".", size); + bytes = (int)str_strlcpy(bufp, ".", size); if (wrptr(&bufp, &size, bytes) != 0) 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); 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) WARN_STATIC_BUFFER(); if (billusion) { @@ -1884,7 +1884,7 @@ nr_building(struct stream *out, const region *r, const building *b, const factio } 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) WARN_STATIC_BUFFER(); } @@ -1899,17 +1899,17 @@ nr_building(struct stream *out, const region *r, const building *b, const factio } i = 0; if (b->display && b->display[0]) { - bytes = (int)strlcpy(bufp, "; ", size); + bytes = (int)str_strlcpy(bufp, "; ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)strlcpy(bufp, b->display, size); + bytes = (int)str_strlcpy(bufp, b->display, size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); i = b->display[strlen(b->display) - 1]; } if (i != '!' && i != '?' && i != '.') { - bytes = (int)strlcpy(bufp, ".", size); + bytes = (int)str_strlcpy(bufp, ".", size); if (wrptr(&bufp, &size, bytes) != 0) 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); cbdata.maxtravel = maxtravel; 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); return; } @@ -2165,10 +2165,10 @@ report_plaintext(const char *filename, report_context * ctx, WARN_STATIC_BUFFER(); for (op = 0; op != MAXOPTIONS; 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) 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) WARN_STATIC_BUFFER(); @@ -2227,12 +2227,12 @@ report_plaintext(const char *filename, report_context * ctx, requirement *rm = ptype->itype->construction->materials; while (rm->number) { 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) WARN_STATIC_BUFFER(); ++m; if (rm->number) - bytes = (int)strlcpy(bufp, ", ", size); + bytes = (int)str_strlcpy(bufp, ", ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } diff --git a/src/reports.c b/src/reports.c index 54d052396..ff289c8d0 100644 --- a/src/reports.c +++ b/src/reports.c @@ -169,14 +169,14 @@ size_t report_status(const unit * u, const struct locale *lang, char *fsbuf, siz struct locale *wloc = get_locale(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); - len = strlcpy(fsbuf, combatstatus[u->status] + 7, buflen); + len = str_strlcpy(fsbuf, combatstatus[u->status] + 7, buflen); } else { - len = strlcpy(fsbuf, status, buflen); + len = str_strlcpy(fsbuf, status, buflen); } if (fval(u, UFL_NOAID)) { - len += strlcat(fsbuf + len, ", ", buflen - len); - len += strlcat(fsbuf + len, LOC(lang, "status_noaid"), buflen - len); + len += str_strlcat(fsbuf + len, ", ", buflen - len); + len += str_strlcat(fsbuf + len, LOC(lang, "status_noaid"), buflen - len); } return len; @@ -689,7 +689,7 @@ bufunit(const faction * f, const unit * u, unsigned int indent, seen_mode mode, header = 1; } else { - n = (int)strlcpy(bufp, ", ", size); + n = (int)str_strlcpy(bufp, ", ", size); } if (wrptr(&bufp, &size, n) != 0) { 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) { if (f->options & rtype->flag) { 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); @@ -1746,8 +1746,8 @@ const char *trailinto(const region * r, const struct locale *lang) const char *tname = terrain_name(r); size_t sz; - sz = strlcpy(ref, tname, sizeof(ref)); - sz += strlcat(ref + sz, "_trail", sizeof(ref) - sz); + sz = str_strlcpy(ref, tname, sizeof(ref)); + sz += str_strlcat(ref + sz, "_trail", sizeof(ref) - sz); s = LOC(lang, ref); if (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; if (!r) { - len = strlcpy(buffer, "(Chaos)", size); + len = str_strlcpy(buffer, "(Chaos)", size); } else { 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]); pnormalize(&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 : ""); buffer[size - 1] = 0; len = strlen(buffer); diff --git a/src/spells.c b/src/spells.c index 847e4bf50..c4bebb2dd 100644 --- a/src/spells.c +++ b/src/spells.c @@ -62,6 +62,7 @@ #include #include #include +#include #include #include #include @@ -74,7 +75,7 @@ #include #include #include -#include +#include #include #include #include @@ -539,7 +540,7 @@ static int sp_summon_familiar(castorder * co) const race *rc; int sk; int dh, dh1; - size_t bytes; + int bytes; message *msg; char zText[2048], *bufp = zText; size_t size = sizeof(zText) - 1; @@ -597,23 +598,20 @@ static int sp_summon_familiar(castorder * co) } else { if (dh == 0) { - bytes = - strlcpy(bufp, (const char *)LOC(mage->faction->locale, + bytes = (int) str_strlcpy(bufp, (const char *)LOC(mage->faction->locale, "list_and"), size); } else { - bytes = strlcpy(bufp, (const char *)", ", size); + bytes = (int)str_strlcpy(bufp, (const char *)", ", size); } - assert(bytes <= INT_MAX); - if (wrptr(&bufp, &size, (int)bytes) != 0) - WARN_STATIC_BUFFER(); + assert(bytes >= 0); + BUFFER_STRCAT(bufp, size, 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); assert(bytes <= INT_MAX); - if (wrptr(&bufp, &size, (int)bytes) != 0) - WARN_STATIC_BUFFER(); + BUFFER_STRCAT(bufp, size, (int)bytes); } } ADDMSG(&mage->faction->msgs, msg_message("familiar_describe", diff --git a/src/spy.c b/src/spy.c index 999be57aa..8d9d4fe8c 100644 --- a/src/spy.c +++ b/src/spy.c @@ -46,10 +46,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include #include -#include #include #include #include +#include /* libc includes */ #include @@ -101,12 +101,12 @@ void spy_message(int spy, const unit * u, const unit * target) first = 0; } 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)); - strlcat(buf, " ", sizeof(buf)); - strlcat(buf, itoa10(eff_skill(target, sv, target->region)), + str_strlcat(buf, " ", sizeof(buf)); + str_strlcat(buf, itoa10(eff_skill(target, sv, target->region)), sizeof(buf)); } } diff --git a/src/study.c b/src/study.c index 42e602087..561e5b9cb 100644 --- a/src/study.c +++ b/src/study.c @@ -46,12 +46,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include #include -#include #include #include #include #include #include +#include #include #include @@ -409,7 +409,7 @@ int teach_cmd(unit * teacher, struct order *ord) strncat(zOrder, " ", sz - 1); --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) { ADDMSG(&teacher->faction->msgs, diff --git a/src/util/bsdstring.h b/src/util/bsdstring.h index 01d03100b..56772180a 100644 --- a/src/util/bsdstring.h +++ b/src/util/bsdstring.h @@ -6,7 +6,8 @@ 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); -#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 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__) diff --git a/src/util/bsdstring.test.c b/src/util/bsdstring.test.c index 70e8aa8b8..ca400d929 100644 --- a/src/util/bsdstring.test.c +++ b/src/util/bsdstring.test.c @@ -6,49 +6,8 @@ #include #include -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 *suite = CuSuiteNew(); - SUITE_ADD_TEST(suite, test_strlcat); - SUITE_ADD_TEST(suite, test_strlcpy); return suite; } diff --git a/src/util/log.c b/src/util/log.c index 2a7e41831..bae1556ed 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -12,8 +12,8 @@ without prior permission by the authors of Eressea. #include #include "log.h" -#include "bsdstring.h" #include "unicode.h" +#include "strings.h" #include #include @@ -150,7 +150,7 @@ static int check_dupe(const char *format, int level) } dupes = 0; } - strlcpy(last_message, format, sizeof(last_message)); + str_strlcpy(last_message, format, sizeof(last_message)); last_type = level; return 0; } diff --git a/src/util/nrmessage.c b/src/util/nrmessage.c index d613cd714..631ee7193 100644 --- a/src/util/nrmessage.c +++ b/src/util/nrmessage.c @@ -135,7 +135,7 @@ const char *string, int level, const char *section) for (i = 0; i != mtype->nparameters; ++i) { if (i != 0) *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); } @@ -151,7 +151,7 @@ size_t size, const void *userdata) const char *m = translate(nrt->string, userdata, nrt->vars, msg->parameters); if (m) { - return strlcpy((char *)buffer, m, size); + return str_strlcpy((char *)buffer, m, size); } else { log_error("Couldn't render message %s\n", nrt->mtype->name); diff --git a/src/util/path.c b/src/util/path.c index f0243887f..3ede6b4ee 100644 --- a/src/util/path.c +++ b/src/util/path.c @@ -3,7 +3,7 @@ #endif #include "path.h" -#include "bsdstring.h" +#include "strings.h" #include #include @@ -16,11 +16,11 @@ char * path_join(const char *p1, const char *p2, char *dst, size_t len) { sz = strlen(p1); } else { - sz = strlcpy(dst, p1, len); + sz = str_strlcpy(dst, p1, len); } assert(sz < len); dst[sz++] = PATH_DELIM; - strlcpy(dst + sz, p2, len - sz); + str_strlcpy(dst + sz, p2, len - sz); return dst; } diff --git a/src/util/strings.test.c b/src/util/strings.test.c index cff6a5168..87b0375ef 100644 --- a/src/util/strings.test.c +++ b/src/util/strings.test.c @@ -50,6 +50,45 @@ static void test_str_slprintf(CuTest * tc) 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 *suite = CuSuiteNew(); @@ -57,5 +96,7 @@ CuSuite *get_strings_suite(void) SUITE_ADD_TEST(suite, test_str_escape); SUITE_ADD_TEST(suite, test_str_replace); SUITE_ADD_TEST(suite, test_str_slprintf); + SUITE_ADD_TEST(suite, test_str_strlcat); + SUITE_ADD_TEST(suite, test_str_strlcpy); return suite; } diff --git a/src/util/translation.c b/src/util/translation.c index b15a79fe2..da26806fe 100644 --- a/src/util/translation.c +++ b/src/util/translation.c @@ -15,7 +15,7 @@ #include "translation.h" -#include "bsdstring.h" +#include "strings.h" #include "critbit.h" #include "log.h" #include "macros.h" @@ -291,7 +291,7 @@ static const char *parse_string(opstack ** stack, const char *in, if (ic == NULL) return NULL; c = (char *)opop_v(stack); - bytes = (c ? strlcpy(oc, c, size) : 0); + bytes = (c ? str_strlcpy(oc, c, size) : 0); if (bytes < size) oc += bytes; else diff --git a/src/util/umlaut.c b/src/util/umlaut.c index 27f7bc67d..1f9e32b1f 100644 --- a/src/util/umlaut.c +++ b/src/util/umlaut.c @@ -21,7 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "assert.h" #include "log.h" -#include "bsdstring.h" +#include "strings.h" #include "unicode.h" #include @@ -212,7 +212,7 @@ void addtoken(tnode ** root, const char *str, variant id) if (lcs == replace[i].ucs) { char zText[1024]; 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); break; }