From 34c1c87263f0d222021e4851afa0663fc0c9ba3a Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sun, 17 Dec 2023 14:19:18 +0100 Subject: Fixed compiler warning --- FICS/board.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/FICS/board.c b/FICS/board.c index e289c60..00f6d9d 100644 --- a/FICS/board.c +++ b/FICS/board.c @@ -549,6 +549,7 @@ style10(game_state_t *b, move_t *ml) { char tmp[80]; int f, r; + int ret, too_long; int ws, bs; board_calc_strength(b, &ws, &bs); @@ -597,7 +598,8 @@ style10(game_state_t *b, move_t *ml) strcat(bstring, tmp); - sprintf(tmp, "%d %s %s %d %d %d %d %d %d %d %d %s (%s) %s %d\n", + ret = snprintf(tmp, sizeof tmp, "%d %s %s %d %d %d %d %d %d %d %d %s " + "(%s) %s %d\n", b->gameNum, garray[b->gameNum].white_name, garray[b->gameNum].black_name, @@ -623,6 +625,11 @@ style10(game_state_t *b, move_t *ml) : "none"), (orient == WHITE ? 0 : 1)); + too_long = (ret < 0 || (size_t)ret >= sizeof tmp); + if (too_long) { + fprintf(stderr, "FICS: %s: warning: snprintf truncated\n", + __func__); + } strcat(bstring, tmp); sprintf(tmp, ">10<\n"); @@ -724,9 +731,7 @@ style12(game_state_t *b, move_t *ml) !(b->bkmoved || b->bqrmoved), (garray[b->gameNum].numHalfMoves - - (b->lastIrreversable == -1 - ? 0 - : b->lastIrreversable))); + (b->lastIrreversable == -1 ? 0 : b->lastIrreversable))); strcat(bstring, tmp); ret = snprintf(tmp, sizeof tmp, "%d %s %s %d %d %d %d %d %d %d %d %s " -- cgit v1.2.3