security fix: replaced sprintf with snprintf
[xboard.git] / winboard / wgamelist.c
index e582a46..e13bcf0 100644 (file)
@@ -66,7 +66,7 @@ static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct
     struct GameListStats dummy;\r
 \r
     /* Initialize stats (use a dummy variable if caller not interested in them) */\r
-    if( stats == NULL ) { \r
+    if( stats == NULL ) {\r
         stats = &dummy;\r
     }\r
 \r
@@ -124,7 +124,7 @@ static int GameListUpdateTitle( HWND hDlg, char * pszTitle, int item_count, int
 {\r
     char buf[256];\r
 \r
-    sprintf( buf, _("%s - %d/%d games"), pszTitle, item_count, item_total );\r
+    snprintf( buf, sizeof(buf)/sizeof(buf[0]),_("%s - %d/%d games"), pszTitle, item_count, item_total );\r
 \r
     if( stats != 0 ) {\r
         sprintf( buf+strlen(buf), " (%d-%d-%d)", stats->white_wins, stats->black_wins, stats->drawn );\r
@@ -153,7 +153,7 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
   static SnapData sd;\r
 \r
   switch (message) {\r
-  case WM_INITDIALOG: \r
+  case WM_INITDIALOG:\r
     Translate(hDlg, DLG_GameList);\r
     GetWindowText( hDlg, szDlgTitle, sizeof(szDlgTitle) );\r
     szDlgTitle[ sizeof(szDlgTitle)-1 ] = '\0';\r
@@ -203,13 +203,13 @@ GameListDialog(HWND hDlg, UINT message,   WPARAM wParam, LPARAM lParam)
                              newSizeX, newSizeY);\r
        sizeX = newSizeX;\r
        sizeY = newSizeY;\r
-      } else \r
+      } else\r
         GetActualPlacement( gameListDialog, &wpGameList );\r
 \r
     }\r
       GameListUpdateTitle( hDlg, _("Game List"), count, ((ListGame *) gameList.tailPred)->number, &stats ); // [HGM] always update title\r
     return FALSE;\r
-    \r
+\r
   case WM_SIZE:\r
     newSizeX = LOWORD(lParam);\r
     newSizeY = HIWORD(lParam);\r
@@ -230,7 +230,7 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
 \r
   case WM_EXITSIZEMOVE:\r
     return OnExitSizeMove( &sd, hDlg, wParam, lParam );\r
-  \r
+\r
   case WM_GETMINMAXINFO:\r
     /* Prevent resizing window too small */\r
     mmi = (MINMAXINFO *) lParam;\r
@@ -239,7 +239,7 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
     break;\r
 \r
   case WM_COMMAND:\r
-      /* \r
+      /*\r
         [AS]\r
         If <Enter> is pressed while editing the filter, it's better to apply\r
         the filter rather than selecting the current game.\r
@@ -270,7 +270,7 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
        return TRUE;\r
       }\r
       break; /* load the game*/\r
-      \r
+\r
     case OPT_GameListNext:\r
       nItem = SendDlgItemMessage(hDlg, OPT_GameListText, LB_GETCURSEL, 0, 0);\r
       nItem++;\r
@@ -281,7 +281,7 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
       }\r
       SendDlgItemMessage(hDlg, OPT_GameListText, LB_SETCURSEL, nItem, 0);\r
       break; /* load the game*/\r
-      \r
+\r
     case OPT_GameListPrev:\r
       nItem = SendDlgItemMessage(hDlg, OPT_GameListText, LB_GETCURSEL, 0, 0);\r
       nItem--;\r
@@ -297,7 +297,7 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
     case IDC_GameListDoFilter:\r
         {\r
             char filter[MAX_FILTER_LENGTH+1];\r
-            \r
+\r
             if( GetDlgItemText( hDlg, IDC_GameListFilter, filter, sizeof(filter) ) >= 0 ) {\r
                 filter[ sizeof(filter)-1 ] = '\0';\r
                 count = GameListToListBox( hDlg, TRUE, filter, &stats );\r
@@ -311,13 +311,13 @@ GameListDialog(HWND hDlg, UINT message,   WPARAM wParam, LPARAM lParam)
     case OPT_GameListClose:\r
       GameListPopDown();\r
       return TRUE;\r
-      \r
+\r
     case OPT_GameListText:\r
       switch (HIWORD(wParam)) {\r
       case LBN_DBLCLK:\r
        nItem = SendMessage((HWND) lParam, LB_GETCURSEL, 0, 0);\r
        break; /* load the game*/\r
-       \r
+\r
       default:\r
        return FALSE;\r
       }\r
@@ -376,7 +376,7 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
 VOID GameListPopUp(FILE *fp, char *filename)\r
 {\r
   FARPROC lpProc;\r
-  \r
+\r
   gameFile = fp;\r
   if (gameFileName != filename) {\r
     if (gameFileName) free(gameFileName);\r
@@ -407,7 +407,7 @@ VOID GameListPopDown(void)
 VOID GameListHighlight(int index)\r
 {\r
   if (gameListDialog == NULL) return;\r
-  SendDlgItemMessage(gameListDialog, OPT_GameListText, \r
+  SendDlgItemMessage(gameListDialog, OPT_GameListText,\r
     LB_SETCURSEL, index - 1, 0);\r
 }\r
 \r