From ec8d97e7d9b9c0a37f24050162c64dad202521c0 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sun, 17 Dec 2023 13:57:59 +0100 Subject: Fixed compiler warning --- FICS/board.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/FICS/board.c b/FICS/board.c index c1980ce..33d5cd1 100644 --- a/FICS/board.c +++ b/FICS/board.c @@ -660,6 +660,7 @@ style12(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); @@ -706,7 +707,8 @@ style12(game_state_t *b, move_t *ml) : b->lastIrreversable))); 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 + 1), garray[b->gameNum].white_name, garray[b->gameNum].black_name, @@ -732,6 +734,11 @@ style12(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); return 0; -- cgit v1.2.3