From: H.G. Muller Date: Mon, 8 Nov 2010 21:57:56 +0000 (+0100) Subject: Bugfix safeStrCpy patch, WinBoard X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=9d270b7479328210b4f4f47ad3c769c60e4ce200;p=xboard.git Bugfix safeStrCpy patch, WinBoard 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. --- diff --git a/winboard/jaws.c b/winboard/jaws.c index da9950d..d05a78f 100644 --- a/winboard/jaws.c +++ b/winboard/jaws.c @@ -340,7 +340,7 @@ KeyboardEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) if(currentPiece != EmptySquare) { char buf[MSG_SIZ]; n = boards[currentMove][fromY][BOARD_WIDTH-2]; - snprintf(buf, MSG)SIZ,"%d %s%s", n, PieceToName(currentPiece,0), n == 1 ? "" : "s"); + snprintf(buf, MSG_SIZ,"%d %s%s", n, PieceToName(currentPiece,0), n == 1 ? "" : "s"); SayString(buf, TRUE); } } else diff --git a/winboard/wclipbrd.c b/winboard/wclipbrd.c index f091c4a..efa276a 100644 --- a/winboard/wclipbrd.c +++ b/winboard/wclipbrd.c @@ -188,7 +188,7 @@ CopyTextToClipboard(char *text) GlobalFree(hGlobalMem); return FALSE; } - safeStrCpy(lpGlobalMem, text, sizeof(lpGlobalMem)/sizeof(lpGlobalMem[0]) ); + safeStrCpy(lpGlobalMem, text, 1<<20); if (appData.debugMode) { lockCount = GlobalFlags(hGlobalMem) & GMEM_LOCKCOUNT; fprintf(debugFP, "CopyTextToClipboard(): lock count %d\n", lockCount); @@ -347,7 +347,7 @@ PasteTextFromClipboard(char **text) CloseClipboard(); return FALSE; } - safeStrCpy(*text, lpClipMem, sizeof(*text)/sizeof(*text[0]) ); + safeStrCpy(*text, lpClipMem, 1<<20 ); if (appData.debugMode) { lockCount = GlobalFlags(hClipMem) & GMEM_LOCKCOUNT; fprintf(debugFP, "PasteTextFromClipboard(): lock count %d\n", lockCount); diff --git a/winboard/winboard.c b/winboard/winboard.c index f818927..e7916ca 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -5710,12 +5710,12 @@ OpenFileDialog(HWND hwnd, char *write, char *defName, char *defExt, // [HGM] dia if (fileName == NULL) fileName = buf1; if (defName == NULL) { - safeStrCpy(fileName, "*.", sizeof(fileName)/sizeof(fileName[0]) ); + safeStrCpy(fileName, "*.", 3 ); strcat(fileName, defExt); } else { - safeStrCpy(fileName, defName, sizeof(fileName)/sizeof(fileName[0]) ); + safeStrCpy(fileName, defName, MSG_SIZ ); } - if (fileTitle) safeStrCpy(fileTitle, "", sizeof(fileTitle)/sizeof(fileTitle[0]) ); + if (fileTitle) safeStrCpy(fileTitle, "", MSG_SIZ ); if (number) *number = 0; openFileName.lStructSize = sizeof(OPENFILENAME); diff --git a/winboard/wsettings.c b/winboard/wsettings.c index a5d6ce6..643de2a 100644 --- a/winboard/wsettings.c +++ b/winboard/wsettings.c @@ -323,7 +323,7 @@ GetOptionValues(HWND hDlg, ChessProgramState *cps) success = GetDlgItemText( hDlg, 2001+2*i, newText, MSG_SIZ - strlen(cps->option[j].name) - 9 ); if(!success) break; changed = strcmp(cps->option[j].textValue, newText) != 0; - safeStrCpy(cps->option[j].textValue, newText, sizeof(cps->option[j].textValue)/sizeof(cps->option[j].textValue[0]) ); + safeStrCpy(cps->option[j].textValue, newText, MSG_SIZ - (cps->option[j].textValue - cps->option[j].name) ); break; case CheckBox: new = IsDlgButtonChecked( hDlg, 2000+2*i );