forked from github/server
STRLCPY macro redefinition and fixes for gcc. work for monkeys.
This commit is contained in:
parent
681697fd47
commit
c8cbeea660
33
src/battle.c
33
src/battle.c
|
@ -2972,10 +2972,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) {
|
||||||
bufp = STRLCPY(bufp, ", ", &size, "print_header");
|
bufp = STRLCPY(bufp, ", ", size);
|
||||||
}
|
}
|
||||||
if (lastf) {
|
if (lastf) {
|
||||||
bufp = STRLCPY(bufp, lastf, &size, "print_header");
|
bufp = STRLCPY(bufp, lastf, size);
|
||||||
first = true;
|
first = true;
|
||||||
}
|
}
|
||||||
if (seematrix(f, s))
|
if (seematrix(f, s))
|
||||||
|
@ -2987,12 +2987,12 @@ static void print_header(battle * b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (first) {
|
if (first) {
|
||||||
bufp = STRLCPY(bufp, " ", &size, "print_header");
|
bufp = STRLCPY(bufp, " ", size);
|
||||||
bufp = STRLCPY(bufp, LOC(f->locale, "and"), &size, "print_header");
|
bufp = STRLCPY(bufp, LOC(f->locale, "and"), size);
|
||||||
bufp = STRLCPY(bufp, " ", &size, "print_header");
|
bufp = STRLCPY(bufp, " ", size);
|
||||||
}
|
}
|
||||||
if (lastf) {
|
if (lastf) {
|
||||||
bufp = STRLCPY(bufp, lastf, &size, "print_header");
|
bufp = STRLCPY(bufp, lastf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
m = msg_message("battle::starters", "factions", zText);
|
m = msg_message("battle::starters", "factions", zText);
|
||||||
|
@ -3723,7 +3723,6 @@ static int battle_report(battle * b)
|
||||||
faction *fac = bf->faction;
|
faction *fac = bf->faction;
|
||||||
char buf[32 * MAXSIDES];
|
char buf[32 * MAXSIDES];
|
||||||
char *bufp = buf;
|
char *bufp = buf;
|
||||||
size_t bytes;
|
|
||||||
size_t size = sizeof(buf) - 1;
|
size_t size = sizeof(buf) - 1;
|
||||||
message *m;
|
message *m;
|
||||||
|
|
||||||
|
@ -3746,34 +3745,24 @@ static int battle_report(battle * b)
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
|
|
||||||
if (komma) {
|
if (komma) {
|
||||||
bytes = strlcpy(bufp, ", ", size);
|
bufp = STRLCPY(bufp, ", ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
slprintf(buffer, sizeof(buffer), "%s %2d(%s): ",
|
slprintf(buffer, sizeof(buffer), "%s %2d(%s): ",
|
||||||
loc_army, army_index(s), abbrev);
|
loc_army, army_index(s), abbrev);
|
||||||
|
|
||||||
bytes = strlcpy(bufp, buffer, size);
|
bufp = STRLCPY(bufp, buffer, size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
|
|
||||||
for (r = FIGHT_ROW; r != NUMROWS; ++r) {
|
for (r = FIGHT_ROW; r != NUMROWS; ++r) {
|
||||||
if (alive[r]) {
|
if (alive[r]) {
|
||||||
if (l != FIGHT_ROW) {
|
if (l != FIGHT_ROW) {
|
||||||
bytes = strlcpy(bufp, "+", size);
|
bufp = STRLCPY(bufp, "+", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
while (k--) {
|
while (k--) {
|
||||||
bytes = strlcpy(bufp, "0+", size);
|
bufp = STRLCPY(bufp, "0+", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
sprintf(buffer, "%d", alive[r]);
|
sprintf(buffer, "%d", alive[r]);
|
||||||
|
|
||||||
bytes = strlcpy(bufp, buffer, size);
|
bufp = STRLCPY(bufp, buffer, size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
|
|
||||||
k = 0;
|
k = 0;
|
||||||
l = r + 1;
|
l = r + 1;
|
||||||
|
|
|
@ -2330,7 +2330,7 @@ static bool display_race(faction * f, unit * u, const race * rc)
|
||||||
info = LOC(f->locale, mkname("raceinfo", "no_info"));
|
info = LOC(f->locale, mkname("raceinfo", "no_info"));
|
||||||
}
|
}
|
||||||
|
|
||||||
bufp = STRLCPY(bufp, info, &size, "display_race");
|
bufp = STRLCPY(bufp, info, size);
|
||||||
|
|
||||||
/* hp_p : Trefferpunkte */
|
/* hp_p : Trefferpunkte */
|
||||||
bytes =
|
bytes =
|
||||||
|
@ -2402,11 +2402,9 @@ static bool display_race(faction * f, unit * u, const race * rc)
|
||||||
for (a = 0; a < RACE_ATTACKS; a++) {
|
for (a = 0; a < RACE_ATTACKS; a++) {
|
||||||
if (rc->attack[a].type != AT_NONE) {
|
if (rc->attack[a].type != AT_NONE) {
|
||||||
if (a != 0)
|
if (a != 0)
|
||||||
bytes = strlcpy(bufp, ", ", size);
|
bufp = STRLCPY(bufp, ", ", size);
|
||||||
else
|
else
|
||||||
bytes = strlcpy(bufp, ": ", size);
|
bufp = STRLCPY(bufp, ": ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
|
|
||||||
switch (rc->attack[a].type) {
|
switch (rc->attack[a].type) {
|
||||||
case AT_STANDARD:
|
case AT_STANDARD:
|
||||||
|
|
12
src/move.c
12
src/move.c
|
@ -1172,17 +1172,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) {
|
||||||
bufp = STRLCPY(bufp, " ", &size, "cycle_route");
|
bufp = STRLCPY_EX(bufp, " ", &size, "cycle_route");
|
||||||
}
|
}
|
||||||
bufp = STRLCPY(bufp, loc, &size, "cycle_route");
|
bufp = STRLCPY_EX(bufp, loc, &size, "cycle_route");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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]);
|
||||||
bufp = STRLCPY(bufp, " ", &size, "cycle_route");
|
bufp = STRLCPY_EX(bufp, " ", &size, "cycle_route");
|
||||||
bufp = STRLCPY(bufp, loc, &size, "cycle_route");
|
bufp = STRLCPY_EX(bufp, loc, &size, "cycle_route");
|
||||||
paused = true;
|
paused = true;
|
||||||
}
|
}
|
||||||
else if (pause) {
|
else if (pause) {
|
||||||
|
@ -2562,8 +2562,8 @@ 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) {
|
||||||
const char *loc = LOC(u->faction->locale, directions[dir]);
|
const char *loc = LOC(u->faction->locale, directions[dir]);
|
||||||
bufp = STRLCPY(bufp, " ", &size, "hunt");
|
bufp = STRLCPY_EX(bufp, " ", &size, "hunt");
|
||||||
bufp = STRLCPY(bufp, loc, &size, "hunt");
|
bufp = STRLCPY_EX(bufp, loc, &size, "hunt");
|
||||||
moves++;
|
moves++;
|
||||||
rc = rconnect(rc, dir);
|
rc = rconnect(rc, dir);
|
||||||
}
|
}
|
||||||
|
|
315
src/reports.c
315
src/reports.c
|
@ -225,26 +225,19 @@ const char **name, const char **basename, int *number, bool singular)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ORDERS_IN_NR 1
|
#define ORDERS_IN_NR 1
|
||||||
static size_t buforder(char *bufp, size_t size, const order * ord, int mode)
|
static size_t buforder(char *buffer, size_t size, const order * ord, int mode)
|
||||||
{
|
{
|
||||||
size_t tsize = 0;
|
char *bufp = buffer;
|
||||||
size_t bytes;
|
|
||||||
|
|
||||||
bytes = strlcpy(bufp, ", \"", size);
|
bufp = STRLCPY(bufp, ", \"", size);
|
||||||
tsize += bytes;
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
if (mode < ORDERS_IN_NR) {
|
if (mode < ORDERS_IN_NR) {
|
||||||
char cmd[ORDERSIZE];
|
char cmd[ORDERSIZE];
|
||||||
get_command(ord, cmd, sizeof(cmd));
|
get_command(ord, cmd, sizeof(cmd));
|
||||||
bytes = strlcpy(bufp, cmd, size);
|
bufp = STRLCPY(bufp, cmd, size);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bytes = strlcpy(bufp, "...", size);
|
bufp = STRLCPY(bufp, "...", size);
|
||||||
}
|
}
|
||||||
tsize += bytes;
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
|
|
||||||
if (size > 1) {
|
if (size > 1) {
|
||||||
*bufp++ = '\"';
|
*bufp++ = '\"';
|
||||||
|
@ -253,9 +246,8 @@ static size_t buforder(char *bufp, size_t size, const order * ord, int mode)
|
||||||
else {
|
else {
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
}
|
}
|
||||||
++tsize;
|
|
||||||
|
|
||||||
return tsize;
|
return bufp-buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** create a report of a list of items to a non-owner.
|
/** create a report of a list of items to a non-owner.
|
||||||
|
@ -465,7 +457,6 @@ size_t size)
|
||||||
bool itemcloak = false;
|
bool itemcloak = false;
|
||||||
const curse_type *itemcloak_ct = 0;
|
const curse_type *itemcloak_ct = 0;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
size_t bytes;
|
|
||||||
item results[MAX_INVENTORY];
|
item results[MAX_INVENTORY];
|
||||||
|
|
||||||
itemcloak_ct = ct_find("itemcloak");
|
itemcloak_ct = ct_find("itemcloak");
|
||||||
|
@ -473,9 +464,7 @@ size_t size)
|
||||||
itemcloak = curse_active(get_curse(u->attribs, itemcloak_ct));
|
itemcloak = curse_active(get_curse(u->attribs, itemcloak_ct));
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = strlcpy(bufp, unitname(u), size);
|
bufp = STRLCPY(bufp, unitname(u), size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
|
|
||||||
if (!isbattle) {
|
if (!isbattle) {
|
||||||
attrib *a_otherfaction = a_find(u->attribs, &at_otherfaction);
|
attrib *a_otherfaction = a_find(u->attribs, &at_otherfaction);
|
||||||
|
@ -484,92 +473,61 @@ size_t size)
|
||||||
attrib *a = a_find(u->attribs, &at_group);
|
attrib *a = a_find(u->attribs, &at_group);
|
||||||
if (a) {
|
if (a) {
|
||||||
group *g = (group *)a->data.v;
|
group *g = (group *)a->data.v;
|
||||||
bytes = strlcpy(bufp, ", ", size);
|
bufp = STRLCPY(bufp, ", ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
bufp = STRLCPY(bufp, groupid(g, f), size);
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
bytes = strlcpy(bufp, groupid(g, f), size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (getarnt) {
|
if (getarnt) {
|
||||||
bytes = strlcpy(bufp, ", ", size);
|
bufp = STRLCPY(bufp, ", ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
bufp = STRLCPY(bufp, LOC(f->locale, "anonymous"), size);
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
bytes = strlcpy(bufp, LOC(f->locale, "anonymous"), size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
else if (a_otherfaction) {
|
else if (a_otherfaction) {
|
||||||
faction *otherfaction = get_otherfaction(a_otherfaction);
|
faction *otherfaction = get_otherfaction(a_otherfaction);
|
||||||
if (otherfaction) {
|
if (otherfaction) {
|
||||||
bytes = strlcpy(bufp, ", ", size);
|
bufp = STRLCPY(bufp, ", ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
bufp = STRLCPY(bufp, factionname(otherfaction), size);
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
bytes = strlcpy(bufp, factionname(otherfaction), size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (getarnt) {
|
if (getarnt) {
|
||||||
bytes = strlcpy(bufp, ", ", size);
|
bufp = STRLCPY(bufp, ", ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
bufp = STRLCPY(bufp, LOC(f->locale, "anonymous"), size);
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
bytes = strlcpy(bufp, LOC(f->locale, "anonymous"), size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (a_otherfaction && alliedunit(u, f, HELP_FSTEALTH)) {
|
if (a_otherfaction && alliedunit(u, f, HELP_FSTEALTH)) {
|
||||||
faction *f = get_otherfaction(a_otherfaction);
|
faction *f = get_otherfaction(a_otherfaction);
|
||||||
int result =
|
int result =
|
||||||
(size_t)_snprintf(bufp, size, ", %s (%s)", factionname(f),
|
_snprintf(bufp, size, ", %s (%s)", factionname(f),
|
||||||
factionname(u->faction));
|
factionname(u->faction));
|
||||||
bytes = (size_t)result;
|
if (wrptr(&bufp, &size, result) != 0)
|
||||||
if (result < 0 || wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bytes = strlcpy(bufp, ", ", size);
|
bufp = STRLCPY(bufp, ", ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
bufp = STRLCPY(bufp, factionname(fv), size);
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
bytes = strlcpy(bufp, factionname(fv), size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = strlcpy(bufp, ", ", size);
|
bufp = STRLCPY(bufp, ", ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
|
|
||||||
if (u->faction != f && a_fshidden && a_fshidden->data.ca[0] == 1
|
if (u->faction != f && a_fshidden && a_fshidden->data.ca[0] == 1
|
||||||
&& effskill(u, SK_STEALTH) >= 6) {
|
&& effskill(u, SK_STEALTH) >= 6) {
|
||||||
bytes = strlcpy(bufp, "? ", size);
|
bufp = STRLCPY(bufp, "? ", size);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result = _snprintf(bufp, size, "%d ", u->number);
|
if (wrptr(&bufp, &size, _snprintf(bufp, size, "%d ", u->number)))
|
||||||
bytes = (size_t)result;
|
|
||||||
}
|
|
||||||
if (result < 0 || wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
|
}
|
||||||
|
|
||||||
pzTmp = get_racename(u->attribs);
|
pzTmp = get_racename(u->attribs);
|
||||||
if (pzTmp) {
|
if (pzTmp) {
|
||||||
bytes = strlcpy(bufp, pzTmp, size);
|
bufp = STRLCPY(bufp, pzTmp, size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) {
|
if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) {
|
||||||
bytes = strlcpy(bufp, " (", size);
|
bufp = STRLCPY(bufp, " (", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
bufp = STRLCPY(bufp, racename(f->locale, u, u_race(u)), size);
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
bytes = strlcpy(bufp, racename(f->locale, u, u_race(u)), size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
if (size > 1) {
|
if (size > 1) {
|
||||||
strcpy(bufp++, ")");
|
strcpy(bufp++, ")");
|
||||||
--size;
|
--size;
|
||||||
|
@ -578,16 +536,10 @@ size_t size)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const race *irace = u_irace(u);
|
const race *irace = u_irace(u);
|
||||||
bytes = strlcpy(bufp, racename(f->locale, u, irace), size);
|
bufp = STRLCPY(bufp, racename(f->locale, u, irace), size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
if (u->faction == f && irace != u_race(u)) {
|
if (u->faction == f && irace != u_race(u)) {
|
||||||
bytes = strlcpy(bufp, " (", size);
|
bufp = STRLCPY(bufp, " (", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
bufp = STRLCPY(bufp, racename(f->locale, u, u_race(u)), size);
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
bytes = strlcpy(bufp, racename(f->locale, u, u_race(u)), size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
if (size > 1) {
|
if (size > 1) {
|
||||||
strcpy(bufp++, ")");
|
strcpy(bufp++, ")");
|
||||||
--size;
|
--size;
|
||||||
|
@ -596,42 +548,26 @@ size_t size)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fval(u, UFL_HERO) && (u->faction == f || omniscient(f))) {
|
if (fval(u, UFL_HERO) && (u->faction == f || omniscient(f))) {
|
||||||
bytes = strlcpy(bufp, ", ", size);
|
bufp = STRLCPY(bufp, ", ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
bufp = STRLCPY(bufp, LOC(f->locale, "hero"), size);
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
bytes = strlcpy(bufp, LOC(f->locale, "hero"), size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
/* status */
|
/* status */
|
||||||
|
|
||||||
if (u->number && (u->faction == f || telepath_see || isbattle)) {
|
if (u->number && (u->faction == f || telepath_see || isbattle)) {
|
||||||
const char *c = hp_status(u);
|
const char *c = hp_status(u);
|
||||||
c = c ? LOC(f->locale, c) : 0;
|
c = c ? LOC(f->locale, c) : 0;
|
||||||
bytes = strlcpy(bufp, ", ", size);
|
bufp = STRLCPY(bufp, ", ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
bufp = STRLCPY(bufp, report_kampfstatus(u, f->locale), size);
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
bytes = strlcpy(bufp, report_kampfstatus(u, f->locale), size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
if (c || fval(u, UFL_HUNGER)) {
|
if (c || fval(u, UFL_HUNGER)) {
|
||||||
bytes = strlcpy(bufp, " (", size);
|
bufp = STRLCPY(bufp, " (", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
if (c) {
|
if (c) {
|
||||||
bytes = strlcpy(bufp, c, size);
|
bufp = STRLCPY(bufp, c, size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
if (fval(u, UFL_HUNGER)) {
|
if (fval(u, UFL_HUNGER)) {
|
||||||
if (c) {
|
if (c) {
|
||||||
bytes = strlcpy(bufp, ", ", size);
|
bufp = STRLCPY(bufp, ", ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
bytes = strlcpy(bufp, LOC(f->locale, "unit_hungers"), size);
|
bufp = STRLCPY(bufp, LOC(f->locale, "unit_hungers"), size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
if (size > 1) {
|
if (size > 1) {
|
||||||
strcpy(bufp++, ")");
|
strcpy(bufp++, ")");
|
||||||
|
@ -640,29 +576,22 @@ size_t size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_guard(u, GUARD_ALL) != 0) {
|
if (is_guard(u, GUARD_ALL) != 0) {
|
||||||
bytes = strlcpy(bufp, ", ", size);
|
bufp = STRLCPY(bufp, ", ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
bufp = STRLCPY(bufp, LOC(f->locale, "unit_guards"), size);
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
bytes = strlcpy(bufp, LOC(f->locale, "unit_guards"), size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((b = usiege(u)) != NULL) {
|
if ((b = usiege(u)) != NULL) {
|
||||||
bytes = strlcpy(bufp, ", belagert ", size);
|
bufp = STRLCPY(bufp, ", belagert ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
bufp = STRLCPY(bufp, buildingname(b), size);
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
bytes = strlcpy(bufp, buildingname(b), size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dh = 0;
|
dh = 0;
|
||||||
if (u->faction == f || telepath_see) {
|
if (u->faction == f || telepath_see) {
|
||||||
skill *sv;
|
skill *sv;
|
||||||
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
|
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
|
||||||
bytes = spskill(bufp, size, f->locale, u, sv, &dh, 1);
|
size_t bytes = spskill(bufp, size, f->locale, u, sv, &dh, 1);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
assert(bytes <=INT_MAX);
|
||||||
|
if (wrptr(&bufp, &size, (int)bytes) != 0)
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -689,27 +618,22 @@ size_t size)
|
||||||
report_item(u, itm, f, &ic, NULL, &in, false);
|
report_item(u, itm, f, &ic, NULL, &in, false);
|
||||||
if (in == 0 || ic == NULL)
|
if (in == 0 || ic == NULL)
|
||||||
continue;
|
continue;
|
||||||
bytes = strlcpy(bufp, ", ", size);
|
bufp = STRLCPY(bufp, ", ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
|
|
||||||
if (!dh) {
|
if (!dh) {
|
||||||
result = _snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_inventory"));
|
result = _snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_inventory"));
|
||||||
bytes = (size_t)result;
|
if (wrptr(&bufp, &size, result) != 0)
|
||||||
if (result < 0 || wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
dh = 1;
|
dh = 1;
|
||||||
}
|
}
|
||||||
if (in == 1) {
|
if (in == 1) {
|
||||||
bytes = strlcpy(bufp, ic, size);
|
bufp = STRLCPY(bufp, ic, size);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result = _snprintf(bufp, size, "%d %s", in, ic);
|
if (wrptr(&bufp, &size, _snprintf(bufp, size, "%d %s", in, ic)))
|
||||||
bytes = (size_t)result;
|
|
||||||
}
|
|
||||||
if (result < 0 || wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (u->faction == f || telepath_see) {
|
if (u->faction == f || telepath_see) {
|
||||||
spellbook *book = unit_get_spellbook(u);
|
spellbook *book = unit_get_spellbook(u);
|
||||||
|
@ -718,8 +642,7 @@ size_t size)
|
||||||
quicklist *ql = book->spells;
|
quicklist *ql = book->spells;
|
||||||
int qi, header, maxlevel = effskill(u, SK_MAGIC);
|
int qi, header, maxlevel = effskill(u, SK_MAGIC);
|
||||||
int result = _snprintf(bufp, size, ". Aura %d/%d", get_spellpoints(u), max_spellpoints(u->region, u));
|
int result = _snprintf(bufp, size, ". Aura %d/%d", get_spellpoints(u), max_spellpoints(u->region, u));
|
||||||
size_t bytes = (size_t)result;
|
if (wrptr(&bufp, &size, result) != 0) {
|
||||||
if (result < 0 || wrptr(&bufp, &size, bytes) != 0) {
|
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -729,19 +652,15 @@ size_t size)
|
||||||
int result = 0;
|
int result = 0;
|
||||||
if (!header) {
|
if (!header) {
|
||||||
result = _snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_spells"));
|
result = _snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_spells"));
|
||||||
bytes = (size_t)result;
|
|
||||||
header = 1;
|
header = 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bytes = strlcpy(bufp, ", ", size);
|
result = (int)strlcpy(bufp, ", ", size);
|
||||||
}
|
}
|
||||||
if (result < 0 || wrptr(&bufp, &size, bytes) != 0) {
|
if (wrptr(&bufp, &size, result) != 0) {
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
|
||||||
bytes = strlcpy(bufp, spell_name(sbe->sp, f->locale), size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0) {
|
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
}
|
}
|
||||||
|
bufp = STRLCPY(bufp, spell_name(sbe->sp, f->locale), size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -752,8 +671,7 @@ size_t size)
|
||||||
if (i != MAXCOMBATSPELLS) {
|
if (i != MAXCOMBATSPELLS) {
|
||||||
int result =
|
int result =
|
||||||
_snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_combatspells"));
|
_snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_combatspells"));
|
||||||
size_t bytes = (size_t)result;
|
if (wrptr(&bufp, &size, result) != 0)
|
||||||
if (result < 0 || wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
|
|
||||||
dh = 0;
|
dh = 0;
|
||||||
|
@ -763,30 +681,20 @@ size_t size)
|
||||||
dh = 1;
|
dh = 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bytes = strlcpy(bufp, ", ", size);
|
bufp = STRLCPY(bufp, ", ", size);
|
||||||
if (bytes && wrptr(&bufp, &size, bytes) != 0) {
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
sp = get_combatspell(u, i);
|
sp = get_combatspell(u, i);
|
||||||
if (sp) {
|
if (sp) {
|
||||||
int sl = get_combatspelllevel(u, i);
|
int sl = get_combatspelllevel(u, i);
|
||||||
bytes = strlcpy(bufp, spell_name(sp, u->faction->locale), size);
|
bufp = STRLCPY(bufp, spell_name(sp, u->faction->locale), size);
|
||||||
if (bytes && wrptr(&bufp, &size, bytes) != 0) {
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sl > 0) {
|
if (sl > 0) {
|
||||||
result = _snprintf(bufp, size, " (%d)", sl);
|
result = _snprintf(bufp, size, " (%d)", sl);
|
||||||
bytes = (size_t)result;
|
if (wrptr(&bufp, &size, result) != 0)
|
||||||
if (result < 0 || wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bytes = strlcpy(bufp, LOC(f->locale, "nr_nospells"), size);
|
bufp = STRLCPY(bufp, LOC(f->locale, "nr_nospells"), size);
|
||||||
if (bytes && wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -798,8 +706,8 @@ size_t size)
|
||||||
keyword_t kwd = getkeyword(ord);
|
keyword_t kwd = getkeyword(ord);
|
||||||
if (is_repeated(kwd)) {
|
if (is_repeated(kwd)) {
|
||||||
if (printed < ORDERS_IN_NR) {
|
if (printed < ORDERS_IN_NR) {
|
||||||
bytes = buforder(bufp, size, ord, printed++);
|
int result = (int)buforder(bufp, size, ord, printed++);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
if (wrptr(&bufp, &size, result) != 0)
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -811,8 +719,8 @@ size_t size)
|
||||||
keyword_t kwd = getkeyword(ord);
|
keyword_t kwd = getkeyword(ord);
|
||||||
if (is_repeated(kwd)) {
|
if (is_repeated(kwd)) {
|
||||||
if (printed < ORDERS_IN_NR) {
|
if (printed < ORDERS_IN_NR) {
|
||||||
bytes = buforder(bufp, size, ord, printed++);
|
int result = (int)buforder(bufp, size, ord, printed++);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
if (wrptr(&bufp, &size, result) != 0)
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -825,14 +733,8 @@ size_t size)
|
||||||
|
|
||||||
str = u_description(u, f->locale);
|
str = u_description(u, f->locale);
|
||||||
if (str) {
|
if (str) {
|
||||||
bytes = strlcpy(bufp, "; ", size);
|
bufp = STRLCPY(bufp, "; ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
bufp = STRLCPY(bufp, str, size);
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
|
|
||||||
bytes = strlcpy(bufp, str, size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
|
|
||||||
i = str[strlen(str) - 1];
|
i = str[strlen(str) - 1];
|
||||||
}
|
}
|
||||||
if (i != '!' && i != '?' && i != '.') {
|
if (i != '!' && i != '?' && i != '.') {
|
||||||
|
@ -843,15 +745,9 @@ size_t size)
|
||||||
}
|
}
|
||||||
pzTmp = uprivate(u);
|
pzTmp = uprivate(u);
|
||||||
if (u->faction == f && pzTmp) {
|
if (u->faction == f && pzTmp) {
|
||||||
bytes = strlcpy(bufp, " (Bem: ", size);
|
bufp = STRLCPY(bufp, " (Bem: ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
bufp = STRLCPY(bufp, pzTmp, size);
|
||||||
WARN_STATIC_BUFFER();
|
bufp = STRLCPY(bufp, ")", size);
|
||||||
bytes = strlcpy(bufp, pzTmp, size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
bytes = strlcpy(bufp, ")", size);
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dh = 0;
|
dh = 0;
|
||||||
|
@ -877,8 +773,6 @@ const struct unit * u, struct skill * sv, int *dh, int days)
|
||||||
{
|
{
|
||||||
char *bufp = buffer;
|
char *bufp = buffer;
|
||||||
int i, effsk;
|
int i, effsk;
|
||||||
size_t bytes;
|
|
||||||
size_t tsize = 0;
|
|
||||||
|
|
||||||
if (!u->number)
|
if (!u->number)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -888,65 +782,35 @@ const struct unit * u, struct skill * sv, int *dh, int days)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = strlcpy(bufp, ", ", size);
|
bufp = STRLCPY(bufp, ", ", size);
|
||||||
tsize += bytes;
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
|
|
||||||
if (!*dh) {
|
if (!*dh) {
|
||||||
bytes = strlcpy(bufp, LOC(lang, "nr_skills"), size);
|
bufp = STRLCPY(bufp, LOC(lang, "nr_skills"), size);
|
||||||
tsize += bytes;
|
bufp = STRLCPY(bufp, ": ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
|
|
||||||
bytes = strlcpy(bufp, ": ", size);
|
|
||||||
tsize += bytes;
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
|
|
||||||
*dh = 1;
|
*dh = 1;
|
||||||
}
|
}
|
||||||
bytes = strlcpy(bufp, skillname(sv->id, lang), size);
|
bufp = STRLCPY(bufp, skillname(sv->id, lang), size);
|
||||||
tsize += bytes;
|
bufp = STRLCPY(bufp, " ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
|
|
||||||
bytes = strlcpy(bufp, " ", size);
|
|
||||||
tsize += bytes;
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
|
|
||||||
if (sv->id == SK_MAGIC) {
|
if (sv->id == SK_MAGIC) {
|
||||||
sc_mage *mage = get_mage(u);
|
sc_mage *mage = get_mage(u);
|
||||||
if (mage && mage->magietyp != M_GRAY) {
|
if (mage && mage->magietyp != M_GRAY) {
|
||||||
bytes =
|
bufp = STRLCPY(bufp, LOC(lang, mkname("school",
|
||||||
strlcpy(bufp, LOC(lang, mkname("school",
|
|
||||||
magic_school[mage->magietyp])), size);
|
magic_school[mage->magietyp])), size);
|
||||||
tsize += bytes;
|
bufp = STRLCPY(bufp, " ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
|
|
||||||
bytes = strlcpy(bufp, " ", size);
|
|
||||||
tsize += bytes;
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sv->id == SK_STEALTH && fval(u, UFL_STEALTH)) {
|
if (sv->id == SK_STEALTH && fval(u, UFL_STEALTH)) {
|
||||||
i = u_geteffstealth(u);
|
i = u_geteffstealth(u);
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
bytes = slprintf(bufp, size, "%d/", i);
|
if (wrptr(&bufp, &size, _snprintf(bufp, size, "%d/", i)) != 0)
|
||||||
tsize += bytes;
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
effsk = effskill(u, sv->id);
|
effsk = effskill(u, sv->id);
|
||||||
bytes = slprintf(bufp, size, "%d", effsk);
|
if (wrptr(&bufp, &size, _snprintf(bufp, size, "%d", effsk)) != 0)
|
||||||
tsize += bytes;
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
|
|
||||||
if (u->faction->options & want(O_SHOWSKCHANGE)) {
|
if (u->faction->options & want(O_SHOWSKCHANGE)) {
|
||||||
|
@ -961,13 +825,11 @@ const struct unit * u, struct skill * sv, int *dh, int days)
|
||||||
diff = effsk - oldeff;
|
diff = effsk - oldeff;
|
||||||
|
|
||||||
if (diff != 0) {
|
if (diff != 0) {
|
||||||
bytes = slprintf(bufp, size, " (%s%d)", (diff > 0) ? "+" : "", diff);
|
if (wrptr(&bufp, &size, _snprintf(bufp, size, " (%s%d)", (diff > 0) ? "+" : "", diff)) != 0)
|
||||||
tsize += bytes;
|
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tsize;
|
return bufp-buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void split_paragraph(strlist ** SP, const char *s, unsigned int indent, unsigned int width, char mark)
|
void split_paragraph(strlist ** SP, const char *s, unsigned int indent, unsigned int width, char mark)
|
||||||
|
@ -2327,8 +2189,7 @@ static void eval_resources(struct opstack **stack, const void *userdata)
|
||||||
const char *rname =
|
const char *rname =
|
||||||
resourcename(res->type, (res->number != 1) ? NMF_PLURAL : 0);
|
resourcename(res->type, (res->number != 1) ? NMF_PLURAL : 0);
|
||||||
int result = _snprintf(bufp, size, "%d %s", res->number, LOC(lang, rname));
|
int result = _snprintf(bufp, size, "%d %s", res->number, LOC(lang, rname));
|
||||||
size_t bytes = (size_t)result;
|
if (wrptr(&bufp, &size, result) != 0 || size < sizeof(buf) / 2) {
|
||||||
if (result < 0 || wrptr(&bufp, &size, bytes) != 0 || size < sizeof(buf) / 2) {
|
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2367,9 +2228,7 @@ static void eval_regions(struct opstack **stack, const void *userdata)
|
||||||
}
|
}
|
||||||
for (i = begin; i < end; ++i) {
|
for (i = begin; i < end; ++i) {
|
||||||
const char *rname = (const char *)regionname(regions->regions[i], report);
|
const char *rname = (const char *)regionname(regions->regions[i], report);
|
||||||
size_t bytes = strlcpy(bufp, rname, size);
|
bufp = STRLCPY(bufp, rname, size);
|
||||||
if (bytes && wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
|
|
||||||
if (i + 1 < end && size > 2) {
|
if (i + 1 < end && size > 2) {
|
||||||
strcat(bufp, ", ");
|
strcat(bufp, ", ");
|
||||||
|
@ -2403,22 +2262,16 @@ static void eval_trail(struct opstack **stack, const void *userdata)
|
||||||
region *r = regions->regions[i];
|
region *r = regions->regions[i];
|
||||||
const char *trail = trailinto(r, lang);
|
const char *trail = trailinto(r, lang);
|
||||||
const char *rn = f_regionid_s(r, report);
|
const char *rn = f_regionid_s(r, report);
|
||||||
int result = _snprintf(bufp, size, trail, rn);
|
|
||||||
size_t bytes = (size_t)result;
|
if (wrptr(&bufp, &size, _snprintf(bufp, size, trail, rn)) != 0)
|
||||||
if (result < 0 || wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
|
|
||||||
if (i + 2 < end) {
|
if (i + 2 < end) {
|
||||||
bytes = strlcpy(bufp, ", ", size);
|
bufp = STRLCPY(bufp, ", ", size);
|
||||||
}
|
}
|
||||||
else if (i + 1 < end) {
|
else if (i + 1 < end) {
|
||||||
bytes = strlcpy(bufp, LOC(lang, "list_and"), size);
|
bufp = STRLCPY(bufp, LOC(lang, "list_and"), size);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
bytes = 0;
|
|
||||||
|
|
||||||
if (bytes && wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*bufp = 0;
|
*bufp = 0;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#include "bsdstring.h"
|
#include "bsdstring.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
@ -66,8 +67,14 @@ char * strlcpy_w(char *dst, const char *src, size_t *siz, const char *err, const
|
||||||
{
|
{
|
||||||
size_t bytes = strlcpy(dst, src, *siz);
|
size_t bytes = strlcpy(dst, src, *siz);
|
||||||
char * buf = dst;
|
char * buf = dst;
|
||||||
if (wrptr(&buf, siz, bytes) != 0)
|
assert(bytes <= INT_MAX);
|
||||||
|
if (wrptr(&buf, siz, (int)bytes) != 0) {
|
||||||
|
if (err) {
|
||||||
log_warning("%s: static buffer too small in %s:%d\n", err, file, line);
|
log_warning("%s: static buffer too small in %s:%d\n", err, file, line);
|
||||||
|
} else {
|
||||||
|
log_warning("static buffer too small in %s:%d\n", file, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ size_t slprintf(char * dst, size_t size, const char * format, ...);
|
||||||
#define WARN_STATIC_BUFFER_EX(foo) log_warning("%s: static buffer too small in %s:%d\n", (foo), __FILE__, __LINE__)
|
#define WARN_STATIC_BUFFER_EX(foo) log_warning("%s: static buffer too small in %s:%d\n", (foo), __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, err) strlcpy_w((dst), (src), (siz), (err), __FILE__, __LINE__)
|
#define STRLCPY(dst, src, siz) strlcpy_w((dst), (src), &(siz), 0, __FILE__, __LINE__)
|
||||||
|
#define STRLCPY_EX(dst, src, siz, err) strlcpy_w((dst), (src), (siz), (err), __FILE__, __LINE__)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue