replace strlcpy/wrptr pairs with new STRLCPY macro.

This commit is contained in:
Enno Rehling 2015-08-17 19:37:02 +02:00
parent 7e64f3177d
commit b999e3c963
3 changed files with 33 additions and 39 deletions

View File

@ -2966,21 +2966,16 @@ static void print_header(battle * b)
side *s;
char *bufp = zText;
size_t size = sizeof(zText) - 1;
size_t bytes;
for (s = b->sides; s != b->sides + b->nsides; ++s) {
fighter *df;
for (df = s->fighters; df; df = df->next) {
if (is_attacker(df)) {
if (first) {
bytes = strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bufp = STRLCPY(bufp, ", ", &size, "print_header");
}
if (lastf) {
bytes = strlcpy(bufp, (const char *)lastf, size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bufp = STRLCPY(bufp, lastf, &size, "print_header");
first = true;
}
if (seematrix(f, s))
@ -2992,20 +2987,12 @@ static void print_header(battle * b)
}
}
if (first) {
bytes = strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = strlcpy(bufp, (const char *)LOC(f->locale, "and"), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bufp = STRLCPY(bufp, " ", &size, "print_header");
bufp = STRLCPY(bufp, LOC(f->locale, "and"), &size, "print_header");
bufp = STRLCPY(bufp, " ", &size, "print_header");
}
if (lastf) {
bytes = strlcpy(bufp, (const char *)lastf, size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bufp = STRLCPY(bufp, lastf, &size, "print_header");
}
m = msg_message("battle::starters", "factions", zText);

View File

@ -1131,7 +1131,6 @@ static const char *shortdirections[MAXDIRECTIONS] = {
static void cycle_route(order * ord, unit * u, int gereist)
{
size_t bytes;
int cm = 0;
char tail[1024], *bufp = tail;
char neworder[2048];
@ -1172,25 +1171,17 @@ static void cycle_route(order * ord, unit * u, int gereist)
if (!pause) {
const char *loc = LOC(lang, shortdirections[d]);
if (bufp != tail) {
bytes = strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bufp = STRLCPY(bufp, " ", &size, "cycle_route");
}
bytes = strlcpy(bufp, loc, size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bufp = STRLCPY(bufp, loc, &size, "cycle_route");
}
}
else if (strlen(neworder) > sizeof(neworder) / 2)
break;
else if (cm == gereist && !paused && pause) {
const char *loc = LOC(lang, parameters[P_PAUSE]);
bytes = strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = strlcpy(bufp, loc, size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bufp = STRLCPY(bufp, " ", &size, "cycle_route");
bufp = STRLCPY(bufp, loc, &size, "cycle_route");
paused = true;
}
else if (pause) {
@ -2568,12 +2559,9 @@ static int hunt(unit * u, order * ord)
}
rc = rconnect(rc, dir);
while (moves < speed && (dir = hunted_dir(rc->attribs, id)) != NODIRECTION) {
bytes = strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = strlcpy(bufp, LOC(u->faction->locale, directions[dir]), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
const char *loc = LOC(u->faction->locale, directions[dir]);
bufp = STRLCPY(bufp, " ", &size, "hunt");
bufp = STRLCPY(bufp, loc, &size, "hunt");
moves++;
rc = rconnect(rc, dir);
}

View File

@ -100,6 +100,17 @@ extern int *storms;
extern int weeks_per_month;
extern int months_per_year;
static void check_errno(const char * file, int line) {
if (errno) {
char zText[64];
sprintf(zText, "error %d during report at %s:%d", errno, file, line);
perror(zText);
errno = 0;
}
}
#define CHECK_ERRNO() check_errno(__FILE__, __LINE__)
static char *gamedate_season(const struct locale *lang)
{
static char buf[256]; // FIXME: static return value
@ -1396,14 +1407,17 @@ static void durchreisende(stream *out, const region * r, const faction * f)
}
}
if (size > 0) {
CHECK_ERRNO();
if (maxtravel == 1) {
bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "has_moved_one"));
}
else {
bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "has_moved_many"));
}
CHECK_ERRNO();
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
WARN_STATIC_BUFFER_EX("durchreisende");
CHECK_ERRNO();
}
*bufp = 0;
paragraph(out, buf, 0, 0, 0);
@ -2206,6 +2220,7 @@ const char *charset)
}
ch = 0;
CHECK_ERRNO();
for (a = a_find(f->attribs, &at_showitem); a && a->type == &at_showitem;
a = a->next) {
const potion_type *ptype =
@ -2258,6 +2273,7 @@ const char *charset)
}
}
newline(out);
CHECK_ERRNO();
centre(out, LOC(f->locale, "nr_alliances"), false);
newline(out);
@ -2265,6 +2281,7 @@ const char *charset)
rpline(out);
CHECK_ERRNO();
anyunits = 0;
for (r = ctx->first; sr == NULL && r != ctx->last; r = r->next) {
@ -2389,6 +2406,7 @@ const char *charset)
newline(out);
rpline(out);
CHECK_ERRNO();
}
if (!is_monsters(f)) {
if (!anyunits) {
@ -2400,6 +2418,7 @@ const char *charset)
}
}
fstream_done(&strm);
CHECK_ERRNO();
return 0;
}