Bugfix safeStrCpy patch, WinBoard
authorH.G. Muller <h.g.muller@hccnet.nl>
Mon, 8 Nov 2010 21:57:56 +0000 (22:57 +0100)
committerH.G. Muller <h.g.muller@hccnet.nl>
Tue, 9 Nov 2010 13:41:30 +0000 (14:41 +0100)
The use of sizeof on pointers was detected through the same method as
the previous patches, this time while compiling WinBoard. A typo in
jaws.c was fixed as well.

winboard/jaws.c
winboard/wclipbrd.c
winboard/winboard.c
winboard/wsettings.c

index da9950d..d05a78f 100644 (file)
@@ -340,7 +340,7 @@ KeyboardEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                if(currentPiece != EmptySquare) {\r
                        char buf[MSG_SIZ];\r
                        n = boards[currentMove][fromY][BOARD_WIDTH-2];\r
-                       snprintf(buf, MSG)SIZ,"%d %s%s", n, PieceToName(currentPiece,0), n == 1 ? "" : "s");\r
+                       snprintf(buf, MSG_SIZ,"%d %s%s", n, PieceToName(currentPiece,0), n == 1 ? "" : "s");\r
                        SayString(buf, TRUE);\r
                }\r
        } else\r
index f091c4a..efa276a 100644 (file)
@@ -188,7 +188,7 @@ CopyTextToClipboard(char *text)
     GlobalFree(hGlobalMem);\r
     return FALSE;\r
   }\r
-  safeStrCpy(lpGlobalMem, text, sizeof(lpGlobalMem)/sizeof(lpGlobalMem[0]) );\r
+  safeStrCpy(lpGlobalMem, text, 1<<20);\r
   if (appData.debugMode) {\r
     lockCount = GlobalFlags(hGlobalMem) & GMEM_LOCKCOUNT;\r
     fprintf(debugFP, "CopyTextToClipboard(): lock count %d\n", lockCount);\r
@@ -347,7 +347,7 @@ PasteTextFromClipboard(char **text)
     CloseClipboard();\r
     return FALSE;\r
   }\r
-  safeStrCpy(*text, lpClipMem, sizeof(*text)/sizeof(*text[0]) );\r
+  safeStrCpy(*text, lpClipMem, 1<<20 );\r
   if (appData.debugMode) {\r
     lockCount = GlobalFlags(hClipMem) & GMEM_LOCKCOUNT;\r
     fprintf(debugFP, "PasteTextFromClipboard(): lock count %d\n", lockCount);\r
index f818927..e7916ca 100644 (file)
@@ -5710,12 +5710,12 @@ OpenFileDialog(HWND hwnd, char *write, char *defName, char *defExt, // [HGM] dia
 \r
   if (fileName == NULL) fileName = buf1;\r
   if (defName == NULL) {\r
-    safeStrCpy(fileName, "*.", sizeof(fileName)/sizeof(fileName[0]) );\r
+    safeStrCpy(fileName, "*.", 3 );\r
     strcat(fileName, defExt);\r
   } else {\r
-    safeStrCpy(fileName, defName, sizeof(fileName)/sizeof(fileName[0]) );\r
+    safeStrCpy(fileName, defName, MSG_SIZ );\r
   }\r
-    if (fileTitle) safeStrCpy(fileTitle, "", sizeof(fileTitle)/sizeof(fileTitle[0]) );\r
+    if (fileTitle) safeStrCpy(fileTitle, "", MSG_SIZ );\r
   if (number) *number = 0;\r
 \r
   openFileName.lStructSize       = sizeof(OPENFILENAME);\r
index a5d6ce6..643de2a 100644 (file)
@@ -323,7 +323,7 @@ GetOptionValues(HWND hDlg, ChessProgramState *cps)
                success = GetDlgItemText( hDlg, 2001+2*i, newText, MSG_SIZ - strlen(cps->option[j].name) - 9 );\r
                if(!success) break;\r
                changed = strcmp(cps->option[j].textValue, newText) != 0;\r
-               safeStrCpy(cps->option[j].textValue, newText, sizeof(cps->option[j].textValue)/sizeof(cps->option[j].textValue[0]) );\r
+               safeStrCpy(cps->option[j].textValue, newText, MSG_SIZ - (cps->option[j].textValue - cps->option[j].name) );\r
                break;\r
            case CheckBox:\r
                new = IsDlgButtonChecked( hDlg, 2000+2*i );\r