diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-04-13 23:30:21 +0200 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-04-13 23:30:21 +0200 |
commit | e063804b8058748a58e394713bf176078aaaf9d4 (patch) | |
tree | 472bc84b050c7d94ad25b4044b58d4ad4234ae04 /FICS/board.c | |
parent | e0f87d06b5e83287c6db100d30c2d3accc7aca90 (diff) |
Added parameter 'bufsize' to append_holding_machine() and append_holding_display() and replaced remaining strcat() calls with mstrlcat()
Diffstat (limited to 'FICS/board.c')
-rw-r--r-- | FICS/board.c | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/FICS/board.c b/FICS/board.c index b754ffc..f09a022 100644 --- a/FICS/board.c +++ b/FICS/board.c @@ -147,7 +147,7 @@ holding_str(int *holding) } PRIVATE char * -append_holding_machine(char *buf, int g, int c, int p) +append_holding_machine(char *buf, const size_t bufsize, int g, int c, int p) { char tmp[50]; game_state_t *gs = &garray[g].game_state; @@ -155,25 +155,26 @@ append_holding_machine(char *buf, int g, int c, int p) msnprintf(tmp, sizeof tmp, "<b1> game %d white [%s] black [", (g + 1), holding_str(gs->holding[0])); mstrlcat(tmp, holding_str(gs->holding[1]), sizeof tmp); - strcat(buf, tmp); + mstrlcat(buf, tmp, bufsize); if (p) { msnprintf(tmp, sizeof tmp, "] <- %c%s\n", "WB"[c], wpstring[p]); - strcat(buf, tmp); + mstrlcat(buf, tmp, bufsize); } else - strcat(buf, "]\n"); + mstrlcat(buf, "]\n", bufsize); return buf; } PRIVATE char * -append_holding_display(char *buf, game_state_t *gs, int white) +append_holding_display(char *buf, const size_t bufsize, game_state_t *gs, + int white) { if (white) - strcat(buf, "White holding: ["); + mstrlcat(buf, "White holding: [", bufsize); else - strcat(buf, "Black holding: ["); - strcat(buf, holding_str(gs->holding[white ? 0 : 1])); - strcat(buf, "]\n"); + mstrlcat(buf, "Black holding: [", bufsize); + mstrlcat(buf, holding_str(gs->holding[white ? 0 : 1]), bufsize); + mstrlcat(buf, "]\n", bufsize); return buf; } @@ -198,7 +199,7 @@ update_holding(int g, int pieceCaptured) gs->holding[c][p - 1]++; tmp1[0] = '\0'; - append_holding_machine(tmp1, g, c, p); + append_holding_machine(tmp1, sizeof tmp1, g, c, p); msnprintf(tmp2, sizeof tmp2, "Game %d %s received: %s -> [%s]\n", (g + 1), @@ -242,15 +243,18 @@ board_to_string(char *wn, char *bn, int wt, int bt, game_state_t *b, move_t *ml, } else bstring[0] = '\0'; - if (bh && !IsMachineStyle(style)) - append_holding_display(bstring, b, (orientation == BLACK)); + if (bh && !IsMachineStyle(style)) { + append_holding_display(bstring, sizeof bstring, b, + (orientation == BLACK)); + } if (styleFuncs[style] (b, ml)) return NULL; if (bh) { - if (IsMachineStyle(style)) - append_holding_machine(bstring, b->gameNum, 0, 0); - else { - append_holding_display(bstring, b, + if (IsMachineStyle(style)) { + append_holding_machine(bstring, sizeof bstring, + b->gameNum, 0, 0); + } else { + append_holding_display(bstring, sizeof bstring, b, (orientation == WHITE)); } } |