From eec82cc2a68e5c0233e25d0f43667e7365bf9364 Mon Sep 17 00:00:00 2001 From: Don HO Date: Fri, 22 Feb 2019 13:37:11 +0100 Subject: [PATCH] [EU-FOSSA] Replace "lstrcpy" by "wcscpy_s" in "BabyGrid.cpp" to avoid the eventual crash --- PowerEditor/src/WinControls/Grid/BabyGrid.cpp | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/PowerEditor/src/WinControls/Grid/BabyGrid.cpp b/PowerEditor/src/WinControls/Grid/BabyGrid.cpp index ebb0a655..9bf016d2 100644 --- a/PowerEditor/src/WinControls/Grid/BabyGrid.cpp +++ b/PowerEditor/src/WinControls/Grid/BabyGrid.cpp @@ -357,6 +357,7 @@ void DisplayTitle(HWND hWnd,int SI,HFONT hfont) ReleaseDC(hWnd,gdc); } +const size_t bufferLen = 1000; void DisplayColumn(HWND hWnd,int SI,int c,int offset,HFONT hfont,HFONT hcolumnheadingfont) { @@ -364,7 +365,7 @@ void DisplayColumn(HWND hWnd,int SI,int c,int offset,HFONT hfont,HFONT hcolumnhe RECT rect,rectsave; HFONT holdfont; int r; - TCHAR buffer[1000]; + TCHAR buffer[bufferLen]; int iDataType,iProtection,iProperty; if(BGHS[SI].columnwidths[c]==0){return;} @@ -418,7 +419,7 @@ void DisplayColumn(HWND hWnd,int SI,int c,int offset,HFONT hfont,HFONT hcolumnhe } SetCell(&BGcell,r,c); - lstrcpy(buffer, TEXT("")); + wcscpy_s(buffer, TEXT("")); if(BGHS[SI].COLUMNSNUMBERED) { if(c>0) @@ -467,7 +468,7 @@ void DisplayColumn(HWND hWnd,int SI,int c,int offset,HFONT hfont,HFONT hcolumnhe rect.bottom = rect.top + BGHS[SI].rowheight; rectsave=rect; SetCell(&BGcell,r,c); - lstrcpy(buffer, TEXT("")); + wcscpy_s(buffer, TEXT("")); if((c==0)&&(BGHS[SI].ROWSNUMBERED)) { wsprintf(buffer, TEXT("%d"), r); @@ -1150,7 +1151,7 @@ void CloseEdit(HWND hWnd,int SI) cell.row = r; cell.col = c; SendMessage(hWnd, BGM_SETCELLDATA, reinterpret_cast(&cell), reinterpret_cast(BGHS[SI].editstring)); - lstrcpy(BGHS[SI].editstring, TEXT("")); + wcscpy_s(BGHS[SI].editstring, TEXT("")); RefreshGrid(hWnd); BGHS[SI].EDITING = FALSE; HideCaret(hWnd); @@ -1222,7 +1223,7 @@ ATOM RegisterGridClass(HINSTANCE hInstance) { BGHS[j].gridmenu = 0; BGHS[j].hlist1 = NULL; - lstrcpy(BGHS[j].protect, TEXT("U")); + wcscpy_s(BGHS[j].protect, TEXT("U")); BGHS[j].rows = 100; BGHS[j].cols = 255; BGHS[j].homerow = 1; @@ -1261,7 +1262,7 @@ ATOM RegisterGridClass(HINSTANCE hInstance) BGHS[j].hcolumnheadingfont = NULL; BGHS[j].htitlefont = NULL; BGHS[j].INITIALCONTENT = FALSE; - lstrcpy(BGHS[j].editstring, TEXT("")); + wcscpy_s(BGHS[j].editstring, TEXT("")); for(int k = 0 ; k < MAX_COLS ; k++) { @@ -1303,7 +1304,7 @@ int FindLongestLine(HDC hdc,TCHAR* text,SIZE* size) TCHAR temptext[1000]; TCHAR *p; - lstrcpy(temptext,text); + wcscpy_s(temptext,text); p = generic_strtok(temptext, TEXT("\n")); while(p) { @@ -1323,7 +1324,7 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; - const size_t bufferLen = 1000; + TCHAR buffer[bufferLen]; int SelfIndex; int ReturnValue; @@ -1413,11 +1414,11 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) HFONT holdfont; if(lstrlen((TCHAR*)lParam)>300) { - lstrcpy(BGHS[SelfIndex].title, TEXT("Title too long (300 chars max)")); + wcscpy_s(BGHS[SelfIndex].title, TEXT("Title too long (300 chars max)")); } else { - lstrcpy(BGHS[SelfIndex].title,(TCHAR*)lParam); + wcscpy_s(BGHS[SelfIndex].title,(TCHAR*)lParam); } gdc=GetDC(hWnd); @@ -1600,11 +1601,11 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case BGM_SETPROTECT: if((BOOL)wParam) { - lstrcpy(BGHS[SelfIndex].protect, TEXT("P")); + wcscpy_s(BGHS[SelfIndex].protect, TEXT("P")); } else { - lstrcpy(BGHS[SelfIndex].protect, TEXT("U")); + wcscpy_s(BGHS[SelfIndex].protect, TEXT("U")); } break; @@ -1731,7 +1732,7 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int count=1; TCHAR tbuffer[255]; - lstrcpy(tbuffer,(TCHAR*)lParam); + wcscpy_s(tbuffer,(TCHAR*)lParam); for(int j=0;j<(int)lstrlen(tbuffer);j++) { if(tbuffer[j]=='\n'){count++;} @@ -1808,7 +1809,7 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } int j,k,c; TCHAR tbuffer[1000]; - lstrcpy(tbuffer,buffer); + wcscpy_s(tbuffer,buffer); k=lstrlen(tbuffer); c=0; for(j=13;jlpszName); + wcscpy_s(BGHS[BG_GridIndex].title,lpcs->lpszName); SendMessage(hWnd, WM_SETTEXT, 0, reinterpret_cast(lpcs->lpszName));