quickly fix gcc conversion warnings. lots of DRY.

This commit is contained in:
Enno Rehling 2015-08-17 20:17:02 +02:00
parent b999e3c963
commit 1042c94fd9
2 changed files with 20 additions and 22 deletions

View File

@ -2320,7 +2320,8 @@ static bool display_race(faction * f, unit * u, const race * rc)
name = rc_name_s(rc, NAME_SINGULAR); name = rc_name_s(rc, NAME_SINGULAR);
bytes = slprintf(bufp, size, "%s: ", LOC(f->locale, name)); bytes = slprintf(bufp, size, "%s: ", LOC(f->locale, name));
if (wrptr(&bufp, &size, bytes) != 0) assert(bytes <= INT_MAX);
if (wrptr(&bufp, &size, (int)bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
key = mkname("raceinfo", rc->_name); key = mkname("raceinfo", rc->_name);
@ -2329,36 +2330,38 @@ 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"));
} }
bytes = strlcpy(bufp, info, size); bufp = STRLCPY(bufp, info, &size, "display_race");
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
/* hp_p : Trefferpunkte */ /* hp_p : Trefferpunkte */
bytes = bytes =
slprintf(bufp, size, " %d %s", rc->hitpoints, LOC(f->locale, slprintf(bufp, size, " %d %s", rc->hitpoints, LOC(f->locale,
"stat_hitpoints")); "stat_hitpoints"));
if (wrptr(&bufp, &size, bytes) != 0) assert(bytes <= INT_MAX);
if (wrptr(&bufp, &size, (int)bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
/* b_attacke : Angriff */ /* b_attacke : Angriff */
bytes = bytes =
slprintf(bufp, size, ", %s: %d", LOC(f->locale, "stat_attack"), slprintf(bufp, size, ", %s: %d", LOC(f->locale, "stat_attack"),
(rc->at_default + rc->at_bonus)); (rc->at_default + rc->at_bonus));
if (wrptr(&bufp, &size, bytes) != 0) assert(bytes <= INT_MAX);
if (wrptr(&bufp, &size, (int)bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
/* b_defense : Verteidigung */ /* b_defense : Verteidigung */
bytes = bytes =
slprintf(bufp, size, ", %s: %d", LOC(f->locale, "stat_defense"), slprintf(bufp, size, ", %s: %d", LOC(f->locale, "stat_defense"),
(rc->df_default + rc->df_bonus)); (rc->df_default + rc->df_bonus));
if (wrptr(&bufp, &size, bytes) != 0) assert(bytes <= INT_MAX);
if (wrptr(&bufp, &size, (int)bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
/* b_armor : Rüstung */ /* b_armor : Rüstung */
if (rc->armor > 0) { if (rc->armor > 0) {
bytes = bytes =
slprintf(bufp, size, ", %s: %d", LOC(f->locale, "stat_armor"), rc->armor); slprintf(bufp, size, ", %s: %d", LOC(f->locale, "stat_armor"), rc->armor);
if (wrptr(&bufp, &size, bytes) != 0) assert(bytes <= INT_MAX);
if (wrptr(&bufp, &size, (int)bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
@ -2377,30 +2380,23 @@ static bool display_race(faction * f, unit * u, const race * rc)
} }
} }
if (rc->battle_flags & BF_EQUIPMENT) { if (rc->battle_flags & BF_EQUIPMENT) {
bytes = (size_t)_snprintf(bufp, size, " %s", LOC(f->locale, "stat_equipment")); if (wrptr(&bufp, &size, _snprintf(bufp, size, " %s", LOC(f->locale, "stat_equipment"))) != 0)
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
if (rc->battle_flags & BF_RES_PIERCE) { if (rc->battle_flags & BF_RES_PIERCE) {
bytes = (size_t)_snprintf(bufp, size, " %s", LOC(f->locale, "stat_pierce")); if (wrptr(&bufp, &size, _snprintf(bufp, size, " %s", LOC(f->locale, "stat_pierce"))) != 0)
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
if (rc->battle_flags & BF_RES_CUT) { if (rc->battle_flags & BF_RES_CUT) {
bytes = (size_t)_snprintf(bufp, size, " %s", LOC(f->locale, "stat_cut")); if (wrptr(&bufp, &size, _snprintf(bufp, size, " %s", LOC(f->locale, "stat_cut"))) != 0)
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
if (rc->battle_flags & BF_RES_BASH) { if (rc->battle_flags & BF_RES_BASH) {
bytes = (size_t)_snprintf(bufp, size, " %s", LOC(f->locale, "stat_bash")); if (wrptr(&bufp, &size, _snprintf(bufp, size, " %s", LOC(f->locale, "stat_bash"))) != 0)
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
bytes = if (wrptr(&bufp, &size, _snprintf(bufp, size, " %d %s", at_count, LOC(f->locale, (at_count == 1) ? "stat_attack" : "stat_attacks"))) != 0)
(size_t)_snprintf(bufp, size, " %d %s", at_count, LOC(f->locale,
(at_count == 1) ? "stat_attack" : "stat_attacks"));
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
for (a = 0; a < RACE_ATTACKS; a++) { for (a = 0; a < RACE_ATTACKS; a++) {
@ -2439,7 +2435,8 @@ static bool display_race(faction * f, unit * u, const race * rc)
bytes = 0; bytes = 0;
} }
if (bytes && wrptr(&bufp, &size, bytes) != 0) assert(bytes <= INT_MAX);
if (bytes && wrptr(&bufp, &size, (int)bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
} }

View File

@ -2543,7 +2543,8 @@ static int hunt(unit * u, order * ord)
bufp = command; bufp = command;
bytes = slprintf(bufp, size, "%s %s", LOC(u->faction->locale, keyword(K_MOVE)), LOC(u->faction->locale, directions[dir])); bytes = slprintf(bufp, size, "%s %s", LOC(u->faction->locale, keyword(K_MOVE)), LOC(u->faction->locale, directions[dir]));
if (wrptr(&bufp, &size, bytes) != 0) assert(bytes <= INT_MAX);
if (wrptr(&bufp, &size, (int)bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
moves = 1; moves = 1;