aboutsummaryrefslogtreecommitdiffstats
path: root/FICS
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-01-06 12:14:08 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2024-01-06 12:14:08 +0100
commita35da1b515827a793c3ad02dacb967ce05a68944 (patch)
tree938517f6a71b4cb3d4b6de65bc889b89308e85cd /FICS
parent9541656e47944f5fbdac31bebbbc13dd41b2f378 (diff)
Check for truncation
Diffstat (limited to 'FICS')
-rw-r--r--FICS/algcheck.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/FICS/algcheck.c b/FICS/algcheck.c
index 017c58f..74bcfc9 100644
--- a/FICS/algcheck.c
+++ b/FICS/algcheck.c
@@ -430,6 +430,7 @@ alg_unparse(game_state_t *gs, move_t *mt)
char tmp[20] = { '\0' };
game_state_t fakeMove;
int piece;
+ size_t ret = 0;
static char mStr[20] = { '\0' };
if (mt->fromFile == ALG_DROP) {
@@ -498,7 +499,12 @@ alg_unparse(game_state_t *gs, move_t *mt)
}
snprintf(tmp, sizeof tmp, "%c%d", (mt->toFile + 'a'), (mt->toRank + 1));
- strlcat(mStr, tmp, sizeof mStr);
+ ret = strlcat(mStr, tmp, sizeof mStr);
+
+ if (ret >= sizeof mStr) {
+ fprintf(stderr, "FICS: %s (line %d): warning: "
+ "strlcat() truncated\n", __func__, __LINE__);
+ }
if (piece == PAWN && mt->piecePromotionTo != NOPIECE) {
strlcat(mStr, "=", sizeof mStr); /* = before promoting piece */
@@ -527,8 +533,14 @@ alg_unparse(game_state_t *gs, move_t *mt)
execute_move(&fakeMove, mt, 0);
fakeMove.onMove = CToggle(fakeMove.onMove);
- if (in_check(&fakeMove))
- strlcat(mStr, "+", sizeof mStr);
+ if (in_check(&fakeMove)) {
+ ret = strlcat(mStr, "+", sizeof mStr);
+
+ if (ret >= sizeof mStr) {
+ fprintf(stderr, "FICS: %s (line %d): warning: "
+ "strlcat() truncated\n", __func__, __LINE__);
+ }
+ }
return mStr;
}