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; side *s;
char *bufp = zText; char *bufp = zText;
size_t size = sizeof(zText) - 1; size_t size = sizeof(zText) - 1;
size_t bytes;
for (s = b->sides; s != b->sides + b->nsides; ++s) { for (s = b->sides; s != b->sides + b->nsides; ++s) {
fighter *df; fighter *df;
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) {
bytes = strlcpy(bufp, ", ", size); bufp = STRLCPY(bufp, ", ", &size, "print_header");
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
} }
if (lastf) { if (lastf) {
bytes = strlcpy(bufp, (const char *)lastf, size); bufp = STRLCPY(bufp, lastf, &size, "print_header");
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
first = true; first = true;
} }
if (seematrix(f, s)) if (seematrix(f, s))
@ -2992,20 +2987,12 @@ static void print_header(battle * b)
} }
} }
if (first) { if (first) {
bytes = strlcpy(bufp, " ", size); bufp = STRLCPY(bufp, " ", &size, "print_header");
if (wrptr(&bufp, &size, bytes) != 0) bufp = STRLCPY(bufp, LOC(f->locale, "and"), &size, "print_header");
WARN_STATIC_BUFFER(); bufp = STRLCPY(bufp, " ", &size, "print_header");
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();
} }
if (lastf) { if (lastf) {
bytes = strlcpy(bufp, (const char *)lastf, size); bufp = STRLCPY(bufp, lastf, &size, "print_header");
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
} }
m = msg_message("battle::starters", "factions", zText); 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) static void cycle_route(order * ord, unit * u, int gereist)
{ {
size_t bytes;
int cm = 0; int cm = 0;
char tail[1024], *bufp = tail; char tail[1024], *bufp = tail;
char neworder[2048]; char neworder[2048];
@ -1172,25 +1171,17 @@ static void cycle_route(order * ord, unit * u, int gereist)
if (!pause) { if (!pause) {
const char *loc = LOC(lang, shortdirections[d]); const char *loc = LOC(lang, shortdirections[d]);
if (bufp != tail) { if (bufp != tail) {
bytes = strlcpy(bufp, " ", size); bufp = STRLCPY(bufp, " ", &size, "cycle_route");
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
} }
bytes = strlcpy(bufp, loc, size); bufp = STRLCPY(bufp, loc, &size, "cycle_route");
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
} }
} }
else if (strlen(neworder) > sizeof(neworder) / 2) else if (strlen(neworder) > sizeof(neworder) / 2)
break; break;
else if (cm == gereist && !paused && pause) { else if (cm == gereist && !paused && pause) {
const char *loc = LOC(lang, parameters[P_PAUSE]); const char *loc = LOC(lang, parameters[P_PAUSE]);
bytes = strlcpy(bufp, " ", size); bufp = STRLCPY(bufp, " ", &size, "cycle_route");
if (wrptr(&bufp, &size, bytes) != 0) bufp = STRLCPY(bufp, loc, &size, "cycle_route");
WARN_STATIC_BUFFER();
bytes = strlcpy(bufp, loc, size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
paused = true; paused = true;
} }
else if (pause) { else if (pause) {
@ -2568,12 +2559,9 @@ static int hunt(unit * u, order * ord)
} }
rc = rconnect(rc, dir); rc = rconnect(rc, dir);
while (moves < speed && (dir = hunted_dir(rc->attribs, id)) != NODIRECTION) { while (moves < speed && (dir = hunted_dir(rc->attribs, id)) != NODIRECTION) {
bytes = strlcpy(bufp, " ", size); const char *loc = LOC(u->faction->locale, directions[dir]);
if (wrptr(&bufp, &size, bytes) != 0) bufp = STRLCPY(bufp, " ", &size, "hunt");
WARN_STATIC_BUFFER(); bufp = STRLCPY(bufp, loc, &size, "hunt");
bytes = strlcpy(bufp, LOC(u->faction->locale, directions[dir]), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
moves++; moves++;
rc = rconnect(rc, dir); rc = rconnect(rc, dir);
} }

View File

@ -100,6 +100,17 @@ extern int *storms;
extern int weeks_per_month; extern int weeks_per_month;
extern int months_per_year; 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 *gamedate_season(const struct locale *lang)
{ {
static char buf[256]; // FIXME: static return value 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) { if (size > 0) {
CHECK_ERRNO();
if (maxtravel == 1) { if (maxtravel == 1) {
bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "has_moved_one")); bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "has_moved_one"));
} }
else { else {
bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "has_moved_many")); bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "has_moved_many"));
} }
CHECK_ERRNO();
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER_EX("durchreisende");
CHECK_ERRNO();
} }
*bufp = 0; *bufp = 0;
paragraph(out, buf, 0, 0, 0); paragraph(out, buf, 0, 0, 0);
@ -2206,6 +2220,7 @@ const char *charset)
} }
ch = 0; ch = 0;
CHECK_ERRNO();
for (a = a_find(f->attribs, &at_showitem); a && a->type == &at_showitem; for (a = a_find(f->attribs, &at_showitem); a && a->type == &at_showitem;
a = a->next) { a = a->next) {
const potion_type *ptype = const potion_type *ptype =
@ -2258,6 +2273,7 @@ const char *charset)
} }
} }
newline(out); newline(out);
CHECK_ERRNO();
centre(out, LOC(f->locale, "nr_alliances"), false); centre(out, LOC(f->locale, "nr_alliances"), false);
newline(out); newline(out);
@ -2265,6 +2281,7 @@ const char *charset)
rpline(out); rpline(out);
CHECK_ERRNO();
anyunits = 0; anyunits = 0;
for (r = ctx->first; sr == NULL && r != ctx->last; r = r->next) { for (r = ctx->first; sr == NULL && r != ctx->last; r = r->next) {
@ -2389,6 +2406,7 @@ const char *charset)
newline(out); newline(out);
rpline(out); rpline(out);
CHECK_ERRNO();
} }
if (!is_monsters(f)) { if (!is_monsters(f)) {
if (!anyunits) { if (!anyunits) {
@ -2400,6 +2418,7 @@ const char *charset)
} }
} }
fstream_done(&strm); fstream_done(&strm);
CHECK_ERRNO();
return 0; return 0;
} }