aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/board.c
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-04-13 23:15:06 +0200
committerMarkus Uhlin <markus@nifty-networks.net>2024-04-13 23:15:06 +0200
commite0f87d06b5e83287c6db100d30c2d3accc7aca90 (patch)
tree50a49ad03cc063006bbcff4efaa7f02b717be08d /FICS/board.c
parent6a527405d2307fdd4a514133757a1631389b6fc8 (diff)
Replaced strcat() calls with mstrlcat()
Diffstat (limited to 'FICS/board.c')
-rw-r--r--FICS/board.c149
1 files changed, 81 insertions, 68 deletions
diff --git a/FICS/board.c b/FICS/board.c
index 6dee066..b754ffc 100644
--- a/FICS/board.c
+++ b/FICS/board.c
@@ -154,7 +154,7 @@ 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]));
- strcat(tmp, holding_str(gs->holding[1]));
+ mstrlcat(tmp, holding_str(gs->holding[1]), sizeof tmp);
strcat(buf, tmp);
if (p) {
@@ -290,43 +290,48 @@ genstyle(game_state_t *b, move_t *ml, char *wp[], char *bp[],
inc = 1;
}
- strcat(bstring, top);
+ mstrlcat(bstring, top, sizeof bstring);
for (f = first, count = 7; f != last + inc; f += inc, count--) {
msnprintf(tmp, sizeof tmp, " %d %s", f + 1, start);
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
for (r = last; r != first - inc; r = r - inc) {
if (square_color(r, f) == WHITE)
- strcat(bstring, wsqr);
+ mstrlcat(bstring, wsqr, sizeof bstring);
else
- strcat(bstring, bsqr);
+ mstrlcat(bstring, bsqr, sizeof bstring);
if (piecetype(b->board[r][f]) == NOPIECE) {
- if (square_color(r, f) == WHITE)
- strcat(bstring, bp[0]);
- else
- strcat(bstring, wp[0]);
+ if (square_color(r, f) == WHITE) {
+ mstrlcat(bstring, bp[0],
+ sizeof bstring);
+ } else {
+ mstrlcat(bstring, wp[0],
+ sizeof bstring);
+ }
} else {
if (colorval(b->board[r][f]) == WHITE) {
- strcat(bstring,
- wp[piecetype(b->board[r][f])]);
+ mstrlcat(bstring,
+ wp[piecetype(b->board[r][f])],
+ sizeof bstring);
} else {
- strcat(bstring,
- bp[piecetype(b->board[r][f])]);
+ mstrlcat(bstring,
+ bp[piecetype(b->board[r][f])],
+ sizeof bstring);
}
}
}
msnprintf(tmp, sizeof tmp, "%s", end);
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
switch (count) {
case 7:
msnprintf(tmp, sizeof tmp, " Move # : %d (%s)",
b->moveNum,
CString(b->onMove));
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
break;
case 6:
if (garray[b->gameNum].numHalfMoves > 0) {
@@ -336,7 +341,7 @@ genstyle(game_state_t *b, move_t *ml, char *wp[], char *bp[],
"'%s'",
CString(CToggle(b->onMove)), move_and_time
(&ml[garray[b->gameNum].numHalfMoves - 1]));
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
}
break;
case 5:
@@ -344,39 +349,39 @@ genstyle(game_state_t *b, move_t *ml, char *wp[], char *bp[],
case 4:
msnprintf(tmp, sizeof tmp, " Black Clock : %s",
tenth_str((bTime > 0 ? bTime : 0), 1));
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
break;
case 3:
msnprintf(tmp, sizeof tmp, " White Clock : %s",
tenth_str((wTime > 0 ? wTime : 0), 1));
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
break;
case 2:
msnprintf(tmp, sizeof tmp, " Black Strength : %d",
bs);
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
break;
case 1:
msnprintf(tmp, sizeof tmp, " White Strength : %d",
ws);
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
break;
case 0:
break;
} // switch
- strcat(bstring, "\n");
+ mstrlcat(bstring, "\n", sizeof bstring);
if (count != 0)
- strcat(bstring, mid);
+ mstrlcat(bstring, mid, sizeof bstring);
else
- strcat(bstring, top);
+ mstrlcat(bstring, top, sizeof bstring);
} // for
if (orient == WHITE)
- strcat(bstring, label);
+ mstrlcat(bstring, label, sizeof bstring);
else
- strcat(bstring, blabel);
+ mstrlcat(bstring, blabel, sizeof bstring);
return 0;
}
@@ -679,19 +684,21 @@ style8(game_state_t *b, move_t *ml)
garray[b->gameNum].black_name,
(orient == WHITE ? ":" : "*"));
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
for (r = 0; r < 8; r++) {
for (f = 0; f < 8; f++) {
if (b->board[f][r] == NOPIECE) {
- strcat(bstring, " ");
+ mstrlcat(bstring, " ", sizeof bstring);
} else {
if (colorval(b->board[f][r]) == WHITE) {
- strcat(bstring, wpstring
- [piecetype(b->board[f][r])]);
+ mstrlcat(bstring, wpstring
+ [piecetype(b->board[f][r])],
+ sizeof bstring);
} else {
- strcat(bstring, bpstring
- [piecetype(b->board[f][r])]);
+ mstrlcat(bstring, bpstring
+ [piecetype(b->board[f][r])],
+ sizeof bstring);
}
}
}
@@ -713,7 +720,7 @@ style8(game_state_t *b, move_t *ml)
? tenth_str(ml[garray[b->gameNum].numHalfMoves - 1].tookTime, 0)
: "0:00"));
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
return 0;
}
@@ -730,11 +737,11 @@ style9(game_state_t *b, move_t *ml)
msnprintf(tmp, sizeof tmp, "\nMove %-23s%s\n",
garray[b->gameNum].white_name,
garray[b->gameNum].black_name);
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
msnprintf(tmp, sizeof tmp, "---- -------------- "
"--------------\n");
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
startmove = ((garray[b->gameNum].numHalfMoves - 3) / 2) * 2;
@@ -747,20 +754,20 @@ style9(game_state_t *b, move_t *ml)
while (i < garray[b->gameNum].numHalfMoves && count < 4) {
if (!(i & 0x01)) {
msnprintf(tmp, sizeof tmp, " %2d ", (i / 2 + 1));
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
}
msnprintf(tmp, sizeof tmp, "%-23s", move_and_time(&ml[i]));
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
if (i & 0x01)
- strcat(bstring, "\n");
+ mstrlcat(bstring, "\n", sizeof bstring);
i++;
count++;
}
if (i & 0x01)
- strcat(bstring, "\n");
+ mstrlcat(bstring, "\n", sizeof bstring);
return 0;
}
@@ -777,29 +784,31 @@ style10(game_state_t *b, move_t *ml)
board_calc_strength(b, &ws, &bs);
msnprintf(tmp, sizeof tmp, "<10>\n");
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
for (r = 7; r >= 0; r--) {
- strcat(bstring, "|");
+ mstrlcat(bstring, "|", sizeof bstring);
for (f = 0; f < 8; f++) {
if (b->board[f][r] == NOPIECE) {
- strcat(bstring, " ");
+ mstrlcat(bstring, " ", sizeof bstring);
} else {
if (colorval(b->board[f][r]) == WHITE) {
- strcat(bstring, wpstring
- [piecetype(b->board[f][r])]);
+ mstrlcat(bstring, wpstring
+ [piecetype(b->board[f][r])],
+ sizeof bstring);
} else {
- strcat(bstring, bpstring
- [piecetype(b->board[f][r])]);
+ mstrlcat(bstring, bpstring
+ [piecetype(b->board[f][r])],
+ sizeof bstring);
}
}
}
- strcat(bstring, "|\n");
+ mstrlcat(bstring, "|\n", sizeof bstring);
}
- strcat(bstring, (b->onMove == WHITE ? "W " : "B "));
+ mstrlcat(bstring, (b->onMove == WHITE ? "W " : "B "), sizeof bstring);
if (garray[b->gameNum].numHalfMoves) {
msnprintf(tmp, sizeof tmp, "%d ",
@@ -808,7 +817,7 @@ style10(game_state_t *b, move_t *ml)
msnprintf(tmp, sizeof tmp, "-1 ");
}
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
msnprintf(tmp, sizeof tmp, "%d %d %d %d %d\n",
!(b->wkmoved || b->wkrmoved),
@@ -819,7 +828,7 @@ style10(game_state_t *b, move_t *ml)
(garray[b->gameNum].numHalfMoves -
(b->lastIrreversable == -1 ? 0 : b->lastIrreversable)));
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
ret = snprintf(tmp, sizeof tmp, "%d %s %s %d %d %d %d %d %d %d %d %s "
"(%s) %s %d\n",
@@ -856,10 +865,10 @@ style10(game_state_t *b, move_t *ml)
__func__);
}
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
msnprintf(tmp, sizeof tmp, ">10<\n");
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
return 0;
}
@@ -885,19 +894,21 @@ style11(game_state_t *b, move_t *ml)
garray[b->gameNum].black_name,
(orient == WHITE ? ":" : "*"));
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
for (r = 0; r < 8; r++) {
for (f = 0; f < 8; f++) {
if (b->board[f][r] == NOPIECE) {
- strcat(bstring, " ");
+ mstrlcat(bstring, " ", sizeof bstring);
} else {
if (colorval(b->board[f][r]) == WHITE) {
- strcat(bstring, wpstring
- [piecetype(b->board[f][r])]);
+ mstrlcat(bstring, wpstring
+ [piecetype(b->board[f][r])],
+ sizeof bstring);
} else {
- strcat(bstring, bpstring
- [piecetype(b->board[f][r])]);
+ mstrlcat(bstring, bpstring
+ [piecetype(b->board[f][r])],
+ sizeof bstring);
}
}
}
@@ -919,7 +930,7 @@ style11(game_state_t *b, move_t *ml)
? tenth_str(ml[garray[b->gameNum].numHalfMoves - 1].tookTime, 0)
: "0:00"));
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
return 0;
}
@@ -940,22 +951,24 @@ style12(game_state_t *b, move_t *ml)
for (r = 7; r >= 0; r--) {
for (f = 0; f < 8; f++) {
if (b->board[f][r] == NOPIECE) {
- strcat(bstring, "-");
+ mstrlcat(bstring, "-", sizeof bstring);
} else {
if (colorval(b->board[f][r]) == WHITE) {
- strcat(bstring, wpstring
- [piecetype(b->board[f][r])]);
+ mstrlcat(bstring, wpstring
+ [piecetype(b->board[f][r])],
+ sizeof bstring);
} else {
- strcat(bstring, bpstring
- [piecetype(b->board[f][r])]);
+ mstrlcat(bstring, bpstring
+ [piecetype(b->board[f][r])],
+ sizeof bstring);
}
}
}
- strcat(bstring, " ");
+ mstrlcat(bstring, " ", sizeof bstring);
}
- strcat(bstring, (b->onMove == WHITE ? "W " : "B "));
+ mstrlcat(bstring, (b->onMove == WHITE ? "W " : "B "), sizeof bstring);
if (garray[b->gameNum].numHalfMoves) {
msnprintf(tmp, sizeof tmp, "%d ",
@@ -964,7 +977,7 @@ style12(game_state_t *b, move_t *ml)
msnprintf(tmp, sizeof tmp, "-1 ");
}
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
msnprintf(tmp, sizeof tmp, "%d %d %d %d %d ",
!(b->wkmoved || b->wkrmoved),
@@ -974,7 +987,7 @@ style12(game_state_t *b, move_t *ml)
(garray[b->gameNum].numHalfMoves -
(b->lastIrreversable == -1 ? 0 : b->lastIrreversable)));
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
ret = snprintf(tmp, sizeof tmp, "%d %s %s %d %d %d %d %d %d %d %d %s "
"(%s) %s %d\n",
@@ -1011,7 +1024,7 @@ style12(game_state_t *b, move_t *ml)
__func__);
}
- strcat(bstring, tmp);
+ mstrlcat(bstring, tmp, sizeof bstring);
return 0;
}