aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/movecheck.c
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2023-12-14 23:14:08 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2023-12-14 23:14:08 +0100
commitbfbbfe36220af93835029f6eab7a1bd332bd4e2b (patch)
tree9b5e564bbf11f6b269aaa5a30c449b35fefe0ab5 /FICS/movecheck.c
parentc63c8efd7109ae7695823e4ad612d1f68e0d69c7 (diff)
move_calculate: fixed compiler warnings
Diffstat (limited to 'FICS/movecheck.c')
-rw-r--r--FICS/movecheck.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/FICS/movecheck.c b/FICS/movecheck.c
index 8456e59..453bdee 100644
--- a/FICS/movecheck.c
+++ b/FICS/movecheck.c
@@ -654,6 +654,7 @@ PRIVATE int
move_calculate(game_state_t *gs, move_t *mt, int promote)
{
game_state_t fakeMove;
+ int ret, too_long;
mt->pieceCaptured = gs->board[mt->toFile][mt->toRank];
mt->enPassant = 0; // Don't know yet,
@@ -661,12 +662,20 @@ move_calculate(game_state_t *gs, move_t *mt, int promote)
if (mt->fromFile == ALG_DROP) {
mt->piecePromotionTo = NOPIECE;
- sprintf(mt->moveString, "%s/%c%c-%c%d",
+ ret = snprintf(mt->moveString, sizeof mt->moveString,
+ "%s/%c%c-%c%d",
wpstring[mt->fromRank],
DROP_CHAR,
DROP_CHAR,
mt->toFile + 'a',
mt->toRank + 1);
+
+ too_long = (ret < 0 || (size_t)ret >= sizeof mt->moveString);
+
+ if (too_long) { /* XXX */
+ fprintf(stderr, "FICS: %s: warning: "
+ "snprintf truncated\n", __func__);
+ }
} else {
if (piecetype(gs->board[mt->fromFile][mt->fromRank]) == PAWN &&
(mt->toRank == 0 || mt->toRank == 7)) {
@@ -693,12 +702,20 @@ move_calculate(game_state_t *gs, move_t *mt, int promote)
mt->toFile == 6) {
sprintf(mt->moveString, "o-o");
} else {
- sprintf(mt->moveString, "%s/%c%d-%c%d",
+ ret = snprintf(mt->moveString, sizeof mt->moveString,
+ "%s/%c%d-%c%d",
wpstring[piecetype(gs->board[mt->fromFile][mt->fromRank])],
mt->fromFile + 'a',
mt->fromRank + 1,
mt->toFile + 'a',
mt->toRank + 1);
+
+ too_long = (ret < 0 || (size_t)ret >= sizeof mt->moveString);
+
+ if (too_long) { /* XXX */
+ fprintf(stderr, "FICS: %s: warning: "
+ "snprintf truncated\n", __func__);
+ }
}
}