From 3fec7c440a7d3972d28f294e5f12be81fe22cfaa Mon Sep 17 00:00:00 2001 From: Zigfrid Date: Mon, 28 Aug 2023 13:50:41 +0200 Subject: [PATCH] update sprintf to snprintf for a newer c++ compiler --- examples/AnalyseAllPlaysBin.cpp | 2 +- examples/AnalyseAllPlaysPBN.cpp | 2 +- examples/AnalysePlayBin.cpp | 2 +- examples/AnalysePlayPBN.cpp | 2 +- examples/CalcAllTables.cpp | 2 +- examples/CalcAllTablesPBN.cpp | 2 +- examples/CalcDDtable.cpp | 2 +- examples/CalcDDtablePBN.cpp | 2 +- examples/SolveAllBoards.cpp | 2 +- examples/SolveBoard.cpp | 6 +++--- examples/SolveBoardPBN.cpp | 6 +++--- src/Par.cpp | 32 ++++++++++++++++---------------- 12 files changed, 31 insertions(+), 31 deletions(-) diff --git a/examples/AnalyseAllPlaysBin.cpp b/examples/AnalyseAllPlaysBin.cpp index ee6c1d0d..d4cf5444 100644 --- a/examples/AnalyseAllPlaysBin.cpp +++ b/examples/AnalyseAllPlaysBin.cpp @@ -74,7 +74,7 @@ int main() { match = ComparePlay(&solved.solved[handno], handno); - sprintf(line, "AnalyseAllPlaysBin, hand %d: %s\n", + snprintf(line, sizeof(line), "AnalyseAllPlaysBin, hand %d: %s\n", handno + 1, (match ? "OK" : "ERROR")); PrintHand(line, bo.deals[handno].remainCards); diff --git a/examples/AnalyseAllPlaysPBN.cpp b/examples/AnalyseAllPlaysPBN.cpp index b9f63ebe..9fbfaed1 100644 --- a/examples/AnalyseAllPlaysPBN.cpp +++ b/examples/AnalyseAllPlaysPBN.cpp @@ -68,7 +68,7 @@ int main() { match = ComparePlay(&solved.solved[handno], handno); - sprintf(line, "AnalyseAllPlaysBin, hand %d: %s\n", + snprintf(line, sizeof(line), "AnalyseAllPlaysBin, hand %d: %s\n", handno + 1, (match ? "OK" : "ERROR")); PrintPBNHand(line, bo.deals[handno].remainCards); diff --git a/examples/AnalysePlayBin.cpp b/examples/AnalysePlayBin.cpp index c1929c6a..1643a5a3 100644 --- a/examples/AnalysePlayBin.cpp +++ b/examples/AnalysePlayBin.cpp @@ -68,7 +68,7 @@ int main() match = ComparePlay(&solved, handno); - sprintf(line, "AnalysePlayBin, hand %d: %s\n", + snprintf(line, sizeof(line), "AnalysePlayBin, hand %d: %s\n", handno + 1, (match ? "OK" : "ERROR")); PrintHand(line, dl.remainCards); diff --git a/examples/AnalysePlayPBN.cpp b/examples/AnalysePlayPBN.cpp index 8da25eca..1c898bd3 100644 --- a/examples/AnalysePlayPBN.cpp +++ b/examples/AnalysePlayPBN.cpp @@ -60,7 +60,7 @@ int main() match = ComparePlay(&solved, handno); - sprintf(line, "AnalysePlayPBNBin, hand %d: %s\n", + snprintf(line, sizeof(line), "AnalysePlayPBNBin, hand %d: %s\n", handno + 1, (match ? "OK" : "ERROR")); PrintPBNHand(line, dlPBN.remainCards); diff --git a/examples/CalcAllTables.cpp b/examples/CalcAllTables.cpp index fc186776..e2bfaae5 100644 --- a/examples/CalcAllTables.cpp +++ b/examples/CalcAllTables.cpp @@ -55,7 +55,7 @@ int main() { match = CompareTable(&tableRes.results[handno], handno); - sprintf(line, + snprintf(line, sizeof(line), "CalcDDtable, hand %d: %s\n", handno + 1, (match ? "OK" : "ERROR")); diff --git a/examples/CalcAllTablesPBN.cpp b/examples/CalcAllTablesPBN.cpp index 0ee9ca94..80abfa3a 100644 --- a/examples/CalcAllTablesPBN.cpp +++ b/examples/CalcAllTablesPBN.cpp @@ -54,7 +54,7 @@ int main() { match = CompareTable(&tableRes.results[handno], handno); - sprintf(line, + snprintf(line, sizeof(line), "CalcDDtable, hand %d: %s\n", handno + 1, (match ? "OK" : "ERROR")); diff --git a/examples/CalcDDtable.cpp b/examples/CalcDDtable.cpp index ac1b2645..c2d80f0d 100644 --- a/examples/CalcDDtable.cpp +++ b/examples/CalcDDtable.cpp @@ -48,7 +48,7 @@ int main() match = CompareTable(&table, handno); - sprintf(line, + snprintf(line, sizeof(line), "CalcDDtable, hand %d: %s\n", handno + 1, (match ? "OK" : "ERROR")); diff --git a/examples/CalcDDtablePBN.cpp b/examples/CalcDDtablePBN.cpp index 44cf503d..7ae7d362 100644 --- a/examples/CalcDDtablePBN.cpp +++ b/examples/CalcDDtablePBN.cpp @@ -45,7 +45,7 @@ int main() match = CompareTable(&table, handno); - sprintf(line, + snprintf(line, sizeof(line), "CalcDDtable, hand %d: %s\n", handno + 1, (match ? "OK" : "ERROR")); diff --git a/examples/SolveAllBoards.cpp b/examples/SolveAllBoards.cpp index 15ab3fc8..144e0d55 100644 --- a/examples/SolveAllBoards.cpp +++ b/examples/SolveAllBoards.cpp @@ -64,7 +64,7 @@ int main() { match = CompareFut(&solved.solvedBoard[handno], handno, 3); - sprintf(line, + snprintf(line, sizeof(line), "SolveAllBoards, hand %d: solutions 3 %s\n", handno + 1, (match ? "OK" : "ERROR")); diff --git a/examples/SolveBoard.cpp b/examples/SolveBoard.cpp index 61771c26..f4470db8 100644 --- a/examples/SolveBoard.cpp +++ b/examples/SolveBoard.cpp @@ -77,7 +77,7 @@ int main() match2 = CompareFut(&fut2, handno, solutions); - sprintf(line, + snprintf(line, sizeof(line), "SolveBoard, hand %d: solutions 3 %s, solutions 2 %s\n", handno + 1, (match3 ? "OK" : "ERROR"), @@ -85,9 +85,9 @@ int main() PrintHand(line, dl.remainCards); - sprintf(line, "solutions == 3\n"); + snprintf(line, sizeof(line), "solutions == 3\n"); PrintFut(line, &fut3); - sprintf(line, "solutions == 2\n"); + snprintf(line, sizeof(line), "solutions == 2\n"); PrintFut(line, &fut2); } } diff --git a/examples/SolveBoardPBN.cpp b/examples/SolveBoardPBN.cpp index 28c24a20..747c7689 100644 --- a/examples/SolveBoardPBN.cpp +++ b/examples/SolveBoardPBN.cpp @@ -75,7 +75,7 @@ int main() match2 = CompareFut(&fut2, handno, solutions); - sprintf(line, + snprintf(line, sizeof(line), "SolveBoardPBN, hand %d: solutions 3 %s, solutions 2 %s\n", handno + 1, (match3 ? "OK" : "ERROR"), @@ -83,9 +83,9 @@ int main() PrintPBNHand(line, dlPBN.remainCards); - sprintf(line, "solutions == 3\n"); + snprintf(line, sizeof(line), "solutions == 3\n"); PrintFut(line, &fut3); - sprintf(line, "solutions == 2\n"); + snprintf(line, sizeof(line), "solutions == 2\n"); PrintFut(line, &fut2); } } diff --git a/src/Par.cpp b/src/Par.cpp index 89dbe032..c3935923 100644 --- a/src/Par.cpp +++ b/src/Par.cpp @@ -131,9 +131,9 @@ int STDCALL Par( presp->parScore[1][2] = ' '; presp->parScore[1][3] = '\0'; - sprintf(temp, "%d", sidesRes[0].score); + snprintf(temp, sizeof(temp), "%d", sidesRes[0].score); strcat(presp->parScore[0], temp); - sprintf(temp, "%d", sidesRes[1].score); + snprintf(temp, sizeof(temp), "%d", sidesRes[1].score); strcat(presp->parScore[1], temp); presp->parContractsString[0][0] = 'N'; @@ -163,7 +163,7 @@ int STDCALL Par( strcat(presp->parContractsString[i], seats[sidesRes[i].contracts[k].seats]); - sprintf(temp, "%d", sidesRes[i].contracts[k].level); + snprintf(temp, sizeof(temp), "%d", sidesRes[i].contracts[k].level); buff[0] = static_cast( cardSuit[denom_conv[sidesRes[i].contracts[k].denom]]); buff[1] = 'x'; @@ -189,7 +189,7 @@ int STDCALL Par( + sidesRes[i].contracts[k].level + 6); - sprintf(temp, "%d", n); + snprintf(temp, sizeof(temp), "%d", n); buff[0] = static_cast( cardSuit[denom_conv[sidesRes[i].contracts[k].denom]]); buff[1] = '\0'; @@ -1290,7 +1290,7 @@ int STDCALL SidesPar( for (k = 0; k < sidesRes[i].number; k++) { - sprintf(sidesRes[i].contracts[k], "%d", parm[i].contracts[k].level); + snprintf(sidesRes[i].contracts[k], sizeof(sidesRes[i].contracts[k]), "%d", parm[i].contracts[k].level); switch (parm[i].contracts[k].denom) { case 0: @@ -1342,13 +1342,13 @@ int STDCALL SidesPar( if (parm[i].contracts[k].underTricks > 0) { /* Sacrifice */ - sprintf(buff, "-%d", parm[i].contracts[k].underTricks); + snprintf(buff, sizeof(buff), "-%d", parm[i].contracts[k].underTricks); strcat(sidesRes[i].contracts[k], buff); } else if (parm[i].contracts[k].overTricks > 0) { /* Make */ - sprintf(buff, "+%d", parm[i].contracts[k].overTricks); + snprintf(buff, sizeof(buff), "+%d", parm[i].contracts[k].overTricks); strcat(sidesRes[i].contracts[k], buff); } } @@ -1366,7 +1366,7 @@ int STDCALL ConvertToDealerTextFormat( int k, i; char buff[20]; - sprintf(resp, "Par %d: ", pres->score); + snprintf(resp, sizeof(resp), "Par %d: ", pres->score); for (k = 0; k < pres->number; k++) { @@ -1401,7 +1401,7 @@ int STDCALL ConvertToDealerTextFormat( for (i = 0; i < 10; i++) buff[i] = '\0'; - sprintf(buff, "%d", pres->contracts[k].level); + snprintf(buff, sizeof(buff), "%d", pres->contracts[k].level); strcat(resp, buff); switch (pres->contracts[k].denom) @@ -1431,7 +1431,7 @@ int STDCALL ConvertToDealerTextFormat( strcat(resp, "x-"); for (i = 0; i < 10; i++) buff[i] = '\0'; - sprintf(buff, "%d", pres->contracts[k].underTricks); + snprintf(buff, sizeof(buff), "%d", pres->contracts[k].underTricks); strcat(resp, buff); } else if (pres->contracts[k].overTricks > 0) @@ -1439,7 +1439,7 @@ int STDCALL ConvertToDealerTextFormat( strcat(resp, "+"); for (i = 0; i < 10; i++) buff[i] = '\0'; - sprintf(buff, "%d", pres->contracts[k].overTricks); + snprintf(buff, sizeof(buff), "%d", pres->contracts[k].overTricks); strcat(resp, buff); } } @@ -1460,14 +1460,14 @@ int STDCALL ConvertToSidesTextFormat( if (pres->score == 0) { - sprintf(resp->parText[0], "Par 0"); + snprintf(resp->parText[0], sizeof(resp->parText[0]), "Par 0"); return RETURN_NO_FAULT; } for (i = 0; i < 2; i++) { - sprintf(resp->parText[i], "Par %d: ", (pres + i)->score); + snprintf(resp->parText[i], sizeof(resp->parText[i]), "Par %d: ", (pres + i)->score); for (k = 0; k < (pres + i)->number; k++) { @@ -1502,7 +1502,7 @@ int STDCALL ConvertToSidesTextFormat( for (j = 0; j < 10; j++) buff[j] = '\0'; - sprintf(buff, "%d", (pres + i)->contracts[k].level); + snprintf(buff, sizeof(buff), "%d", (pres + i)->contracts[k].level); strcat(resp->parText[i], buff); switch ((pres + i)->contracts[k].denom) @@ -1532,7 +1532,7 @@ int STDCALL ConvertToSidesTextFormat( strcat(resp->parText[i], "x-"); for (j = 0; j < 10; j++) buff[j] = '\0'; - sprintf(buff, "%d", (pres + i)->contracts[k].underTricks); + snprintf(buff, sizeof(buff), "%d", (pres + i)->contracts[k].underTricks); strcat(resp->parText[i], buff); } else if ((pres + i)->contracts[k].overTricks > 0) @@ -1540,7 +1540,7 @@ int STDCALL ConvertToSidesTextFormat( strcat(resp->parText[i], "+"); for (j = 0; j < 10; j++) buff[j] = '\0'; - sprintf(buff, "%d", (pres + i)->contracts[k].overTricks); + snprintf(buff, sizeof(buff), "%d", (pres + i)->contracts[k].overTricks); strcat(resp->parText[i], buff); } }