Skip to content

Commit a3ca699

Browse files
committed
C++ hardening
1 parent 64a3197 commit a3ca699

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

src/tkscid.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,9 +2586,8 @@ int sc_game_crosstable(ClientData, Tcl_Interp *ti, int argc,
25862586
NULL);
25872587
}
25882588

2589-
char stemp[1000];
2590-
sprintf(stemp, "%s%s%s, ", g->GetEventStr(), newlineStr, g->GetSiteStr());
2591-
Tcl_AppendResult(ti, stemp, NULL);
2589+
char stemp[256];
2590+
Tcl_AppendResult(ti, g->GetEventStr(), newlineStr, g->GetSiteStr(), ", ", NULL);
25922591
date_DecodeToString(firstSeenDate, stemp);
25932592
strTrimDate(stemp);
25942593
Tcl_AppendResult(ti, stemp, NULL);
@@ -2606,7 +2605,7 @@ int sc_game_crosstable(ClientData, Tcl_Interp *ti, int argc,
26062605
appendUintResult(ti, avgElo);
26072606
uint category = ctable->FideCategory(avgElo);
26082607
if (category > 0 && mode == CROSSTABLE_AllPlayAll) {
2609-
sprintf(stemp, " (%s %u)", translate(ti, "Category", "Category"),
2608+
std::snprintf(stemp, sizeof(stemp), " (%s %u)", translate(ti, "Category", "Category"),
26102609
category);
26112610
Tcl_AppendResult(ti, stemp, NULL);
26122611
}
@@ -2911,7 +2910,7 @@ int sc_game_info(ClientData, Tcl_Interp *ti, int argc, const char **argv) {
29112910
Tcl_AppendResult(ti, temp, NULL);
29122911
eloT elo = db->game->GetWhiteElo();
29132912
if (elo != 0) {
2914-
sprintf(temp, " <red>%u</red>", elo);
2913+
std::snprintf(temp, sizeof(temp), " <red>%u</red>", elo);
29152914
Tcl_AppendResult(ti, temp, NULL);
29162915
}
29172916
std::snprintf(temp, sizeof(temp), " -- <pi %s>%s</pi>",
@@ -2923,15 +2922,15 @@ int sc_game_info(ClientData, Tcl_Interp *ti, int argc, const char **argv) {
29232922
Tcl_AppendResult(ti, temp, NULL);
29242923
elo = db->game->GetBlackElo();
29252924
if (elo != 0) {
2926-
sprintf(temp, " <red>%u</red>", elo);
2925+
std::snprintf(temp, sizeof(temp), " <red>%u</red>", elo);
29272926
Tcl_AppendResult(ti, temp, NULL);
29282927
}
29292928

29302929
if (hideNextMove) {
2931-
sprintf(temp, "<br>(%s: %s)", translate(ti, "Result"),
2930+
std::snprintf(temp, sizeof(temp), "<br>(%s: %s)", translate(ti, "Result"),
29322931
translate(ti, "hidden"));
29332932
} else {
2934-
sprintf(temp, "<br>%s <red>(%u)</red>",
2933+
std::snprintf(temp, sizeof(temp), "<br>%s <red>(%u)</red>",
29352934
RESULT_LONGSTR[db->game->GetResult()],
29362935
(db->game->GetNumHalfMoves() + 1) / 2);
29372936
}
@@ -3062,7 +3061,7 @@ int sc_game_info(ClientData, Tcl_Interp *ti, int argc, const char **argv) {
30623061
strAppend(temp, ")");
30633062
printNags = false;
30643063
} else {
3065-
sprintf(temp, "<run ::move::Back>%u.%s%s</run>", prevMoveCount,
3064+
std::snprintf(temp, sizeof(temp), "<run ::move::Back>%u.%s%s</run>", prevMoveCount,
30663065
toMove == WHITE ? ".." : "", tempTrans); // san);
30673066
printNags = true;
30683067
}
@@ -3095,12 +3094,12 @@ int sc_game_info(ClientData, Tcl_Interp *ti, int argc, const char **argv) {
30953094
strAppend(temp, ")");
30963095
printNags = false;
30973096
} else if (hideNextMove) {
3098-
sprintf(temp, "%u.%s(", moveCount, toMove == WHITE ? "" : "..");
3097+
std::snprintf(temp, sizeof(temp), "%u.%s(", moveCount, toMove == WHITE ? "" : "..");
30993098
strAppend(temp, translate(ti, "hidden"));
31003099
strAppend(temp, ")");
31013100
printNags = false;
31023101
} else {
3103-
sprintf(temp, "<run ::move::Forward>%u.%s%s</run>", moveCount,
3102+
std::snprintf(temp, sizeof(temp), "<run ::move::Forward>%u.%s%s</run>", moveCount,
31043103
toMove == WHITE ? "" : "..", tempTrans); // san);
31053104
printNags = true;
31063105
}
@@ -3128,13 +3127,13 @@ int sc_game_info(ClientData, Tcl_Interp *ti, int argc, const char **argv) {
31283127
if (showMaterialValue) {
31293128
uint mWhite = db->game->GetCurrentPos()->MaterialValue(WHITE);
31303129
uint mBlack = db->game->GetCurrentPos()->MaterialValue(BLACK);
3131-
sprintf(temp, " <gray>(%u-%u", mWhite, mBlack);
3130+
std::snprintf(temp, sizeof(temp), " <gray>(%u-%u", mWhite, mBlack);
31323131
Tcl_AppendResult(ti, temp, NULL);
31333132
if (mWhite > mBlack) {
3134-
sprintf(temp, ":+%u", mWhite - mBlack);
3133+
std::snprintf(temp, sizeof(temp), ":+%u", mWhite - mBlack);
31353134
Tcl_AppendResult(ti, temp, NULL);
31363135
} else if (mBlack > mWhite) {
3137-
sprintf(temp, ":-%u", mBlack - mWhite);
3136+
std::snprintf(temp, sizeof(temp), ":-%u", mBlack - mWhite);
31383137
Tcl_AppendResult(ti, temp, NULL);
31393138
}
31403139
Tcl_AppendResult(ti, ")</gray>", NULL);
@@ -3151,13 +3150,13 @@ int sc_game_info(ClientData, Tcl_Interp *ti, int argc, const char **argv) {
31513150
db->game->GetSAN(s);
31523151
strcpy(tempTrans, s);
31533152
transPieces(tempTrans);
3154-
sprintf(temp, " <run sc_var enter %u; updateBoard -animate>v%u", vnum,
3153+
std::snprintf(temp, sizeof(temp), " <run sc_var enter %u; updateBoard -animate>v%u", vnum,
31553154
vnum + 1);
31563155
Tcl_AppendResult(ti, "<green>", temp, "</green>: ", NULL);
31573156
if (s[0] == 0) {
3158-
sprintf(temp, "<darkblue>(empty)</darkblue>");
3157+
std::snprintf(temp, sizeof(temp), "<darkblue>(empty)</darkblue>");
31593158
} else {
3160-
sprintf(temp, "<darkblue>%u.%s%s</darkblue>", moveCount,
3159+
std::snprintf(temp, sizeof(temp), "<darkblue>%u.%s%s</darkblue>", moveCount,
31613160
toMove == WHITE ? "" : "..", tempTrans); // s);
31623161
}
31633162
Tcl_AppendResult(ti, temp, NULL);
@@ -7057,7 +7056,7 @@ UI_res_t sc_name_spellcheck(UI_handle_t ti, scidBaseT &dbase,
70577056
if (i == 0)
70587057
correctionCount++;
70597058

7060-
sprintf(tempStr, "%s\"%s\"\t>> \"%s\" (%u)", strAmbiguous, origName,
7059+
std::snprintf(tempStr, sizeof(tempStr), "%s\"%s\"\t>> \"%s\" (%u)", strAmbiguous, origName,
70617060
corrections[i], frequency);
70627061
correctCmd += tempStr;
70637062

0 commit comments

Comments
 (0)