exchanged some sprintf with snprintf
[xboard.git] / backend.c
index 23ec636..3205cde 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -669,7 +669,7 @@ InitBackEnd1()
     if (!ParseTimeControl(appData.timeControl, appData.timeIncrement,\r
                          appData.movesPerSession)) {\r
        char buf[MSG_SIZ];\r
-       sprintf(buf, _("bad timeControl option %s"), appData.timeControl);\r
+       snprintf(buf, sizeof(buf), _("bad timeControl option %s"), appData.timeControl);\r
        DisplayFatalError(buf, 0, 2);\r
     }\r
 \r
@@ -684,7 +684,7 @@ InitBackEnd1()
            searchTime = min * 60 + sec;\r
        } else {\r
            char buf[MSG_SIZ];\r
-           sprintf(buf, _("bad searchTime option %s"), appData.searchTime);\r
+           snprintf(buf, sizeof(buf), _("bad searchTime option %s"), appData.searchTime);\r
            DisplayFatalError(buf, 0, 2);\r
        }\r
     }\r
@@ -1124,7 +1124,7 @@ InitBackEnd3 P((void))
                sprintf(buf, _("Could not open comm port %s"),  \r
                        appData.icsCommPort);\r
            } else {\r
-               sprintf(buf, _("Could not connect to host %s, port %s"),  \r
+               snprintf(buf, sizeof(buf), _("Could not connect to host %s, port %s"),  \r
                        appData.icsHost, appData.icsPort);\r
            }\r
            DisplayFatalError(buf, err, 1);\r
@@ -1319,18 +1319,18 @@ establish()
     } else if (*appData.gateway != NULLCHAR) {\r
        if (*appData.remoteShell == NULLCHAR) {\r
            /* Use the rcmd protocol to run telnet program on a gateway host */\r
-           sprintf(buf, "%s %s %s",\r
+           snprintf(buf, sizeof(buf), "%s %s %s",\r
                    appData.telnetProgram, appData.icsHost, appData.icsPort);\r
            return OpenRcmd(appData.gateway, appData.remoteUser, buf, &icsPR);\r
 \r
        } else {\r
            /* Use the rsh program to run telnet program on a gateway host */\r
            if (*appData.remoteUser == NULLCHAR) {\r
-               sprintf(buf, "%s %s %s %s %s", appData.remoteShell,\r
+               snprintf(buf, sizeof(buf), "%s %s %s %s %s", appData.remoteShell,\r
                        appData.gateway, appData.telnetProgram,\r
                        appData.icsHost, appData.icsPort);\r
            } else {\r
-               sprintf(buf, "%s %s -l %s %s %s %s",\r
+               snprintf(buf, sizeof(buf), "%s %s -l %s %s %s %s",\r
                        appData.remoteShell, appData.gateway, \r
                        appData.remoteUser, appData.telnetProgram,\r
                        appData.icsHost, appData.icsPort);\r
@@ -2345,7 +2345,7 @@ read_from_ics(isr, closure, data, count, error)
 \r
            if (loggedOn && !have_set_title && ics_handle[0] != NULLCHAR) {\r
              char buf[MSG_SIZ];\r
-             sprintf(buf, "%s@%s", ics_handle, appData.icsHost);\r
+             snprintf(buf, sizeof(buf), "%s@%s", ics_handle, appData.icsHost);\r
              DisplayIcsInteractionTitle(buf);\r
              have_set_title = TRUE;\r
            }\r
@@ -3353,7 +3353,7 @@ ParseBoard12(string)
               &ticking);\r
 \r
     if (n < 21) {\r
-       sprintf(str, _("Failed to parse board string:\n\"%s\""), string);\r
+        snprintf(str, sizeof(str), _("Failed to parse board string:\n\"%s\""), string);\r
        DisplayError(str, 0);\r
        return;\r
     }\r
@@ -6154,7 +6154,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h
     if (!strncmp(message, "tellopponent ", 13)) {\r
       if (appData.icsActive) {\r
        if (loggedOn) {\r
-         sprintf(buf1, "%ssay %s\n", ics_prefix, message + 13);\r
+         snprintf(buf1, sizeof(buf1), "%ssay %s\n", ics_prefix, message + 13);\r
          SendToICS(buf1);\r
        }\r
       } else {\r
@@ -6165,7 +6165,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h
     if (!strncmp(message, "tellothers ", 11)) {\r
       if (appData.icsActive) {\r
        if (loggedOn) {\r
-         sprintf(buf1, "%swhisper %s\n", ics_prefix, message + 11);\r
+         snprintf(buf1, sizeof(buf1), "%swhisper %s\n", ics_prefix, message + 11);\r
          SendToICS(buf1);\r
        }\r
       }\r
@@ -6174,7 +6174,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h
     if (!strncmp(message, "tellall ", 8)) {\r
       if (appData.icsActive) {\r
        if (loggedOn) {\r
-         sprintf(buf1, "%skibitz %s\n", ics_prefix, message + 8);\r
+         snprintf(buf1, sizeof(buf1), "%skibitz %s\n", ics_prefix, message + 8);\r
          SendToICS(buf1);\r
        }\r
       } else {\r
@@ -6344,7 +6344,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h
        || (StrStr(message, "Permission denied") != NULL)) {\r
 \r
        cps->maybeThinking = FALSE;\r
-       sprintf(buf1, _("Failed to start %s chess program %s on %s: %s\n"),\r
+       snprintf(buf1, sizeof(buf1), _("Failed to start %s chess program %s on %s: %s\n"),\r
                cps->which, cps->program, cps->host, message);\r
        RemoveInputSource(cps->isr);\r
        DisplayFatalError(buf1, 0, 1);\r
@@ -6362,11 +6362,11 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h
                (void) CoordsToAlgebraic(boards[forwardMostMove],\r
                                    PosFlags(forwardMostMove), EP_UNKNOWN,\r
                                    fromY, fromX, toY, toX, promoChar, buf1);\r
-               sprintf(buf2, _("Hint: %s"), buf1);\r
+               snprintf(buf2, sizeof(buf2), _("Hint: %s"), buf1);\r
                DisplayInformation(buf2);\r
            } else {\r
                /* Hint move could not be parsed!? */\r
-               sprintf(buf2,\r
+             snprintf(buf2, sizeof(buf2),\r
                        _("Illegal hint move \"%s\"\nfrom %s chess program"),\r
                        buf1, cps->which);\r
                DisplayError(buf2, 0);\r
@@ -7569,7 +7569,7 @@ InitChessProgram(cps, setup)
     }\r
 \r
     if (cps->sendICS) {\r
-      sprintf(buf, "ics %s\n", appData.icsActive ? appData.icsHost : "-");\r
+      snprintf(buf, sizeof(buf), "ics %s\n", appData.icsActive ? appData.icsHost : "-");\r
       SendToProgram(buf, cps);\r
     }\r
     cps->maybeThinking = FALSE;\r
@@ -7617,10 +7617,10 @@ StartChessProgram(cps)
        err = OpenRcmd(cps->host, appData.remoteUser, cps->program, &cps->pr);\r
     } else {\r
        if (*appData.remoteUser == NULLCHAR) {\r
-           sprintf(buf, "%s %s %s", appData.remoteShell, cps->host,\r
+         snprintf(buf, sizeof(buf), "%s %s %s", appData.remoteShell, cps->host,\r
                    cps->program);\r
        } else {\r
-           sprintf(buf, "%s %s -l %s %s", appData.remoteShell,\r
+         snprintf(buf, sizeof(buf), "%s %s -l %s %s", appData.remoteShell,\r
                    cps->host, appData.remoteUser, cps->program);\r
        }\r
        err = StartChildProcess(buf, "", &cps->pr);\r
@@ -8541,7 +8541,7 @@ LoadGameFromFile(filename, n, title, useList)
     } else {\r
        f = fopen(filename, "rb");\r
        if (f == NULL) {\r
-           sprintf(buf, _("Can't open \"%s\""), filename);\r
+         snprintf(buf, sizeof(buf),  _("Can't open \"%s\""), filename);\r
            DisplayError(buf, errno);\r
            return FALSE;\r
        }\r
@@ -8768,7 +8768,7 @@ LoadGame(f, gameNumber, title, useList)
     yynewfile(f);\r
 \r
     if (lg && lg->gameInfo.white && lg->gameInfo.black) {\r
-       sprintf(buf, "%s vs. %s", lg->gameInfo.white,\r
+      snprintf(buf, sizeof(buf), "%s vs. %s", lg->gameInfo.white,\r
                lg->gameInfo.black);\r
            DisplayTitle(buf);\r
     } else if (*title != NULLCHAR) {\r
@@ -9195,7 +9195,7 @@ LoadPositionFromFile(filename, n, title)
     } else {\r
        f = fopen(filename, "rb");\r
        if (f == NULL) {\r
-           sprintf(buf, _("Can't open \"%s\""), filename);\r
+            snprintf(buf, sizeof(buf), _("Can't open \"%s\""), filename);\r
            DisplayError(buf, errno);\r
            return FALSE;\r
        } else {\r
@@ -9409,7 +9409,7 @@ SaveGameToFile(filename, append)
     } else {\r
        f = fopen(filename, append ? "a" : "w");\r
        if (f == NULL) {\r
-           sprintf(buf, _("Can't open \"%s\""), filename);\r
+           snprintf(buf, sizeof(buf), _("Can't open \"%s\""), filename);\r
            DisplayError(buf, errno);\r
            return FALSE;\r
        } else {\r
@@ -9783,7 +9783,7 @@ SavePositionToFile(filename)
     } else {\r
        f = fopen(filename, "a");\r
        if (f == NULL) {\r
-           sprintf(buf, _("Can't open \"%s\""), filename);\r
+           snprintf(buf, sizeof(buf), _("Can't open \"%s\""), filename);\r
            DisplayError(buf, errno);\r
            return FALSE;\r
        } else {\r