[EU-FOSSA] Replace "lstrcpy" by "wcscpy_s" in "BabyGrid.cpp" to avoid the eventual crash

This commit is contained in:
Don HO 2019-02-22 13:37:11 +01:00
parent bd7816755c
commit eec82cc2a6

View File

@ -357,6 +357,7 @@ void DisplayTitle(HWND hWnd,int SI,HFONT hfont)
ReleaseDC(hWnd,gdc); ReleaseDC(hWnd,gdc);
} }
const size_t bufferLen = 1000;
void DisplayColumn(HWND hWnd,int SI,int c,int offset,HFONT hfont,HFONT hcolumnheadingfont) 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; RECT rect,rectsave;
HFONT holdfont; HFONT holdfont;
int r; int r;
TCHAR buffer[1000]; TCHAR buffer[bufferLen];
int iDataType,iProtection,iProperty; int iDataType,iProtection,iProperty;
if(BGHS[SI].columnwidths[c]==0){return;} 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); SetCell(&BGcell,r,c);
lstrcpy(buffer, TEXT("")); wcscpy_s(buffer, TEXT(""));
if(BGHS[SI].COLUMNSNUMBERED) if(BGHS[SI].COLUMNSNUMBERED)
{ {
if(c>0) 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; rect.bottom = rect.top + BGHS[SI].rowheight;
rectsave=rect; rectsave=rect;
SetCell(&BGcell,r,c); SetCell(&BGcell,r,c);
lstrcpy(buffer, TEXT("")); wcscpy_s(buffer, TEXT(""));
if((c==0)&&(BGHS[SI].ROWSNUMBERED)) if((c==0)&&(BGHS[SI].ROWSNUMBERED))
{ {
wsprintf(buffer, TEXT("%d"), r); wsprintf(buffer, TEXT("%d"), r);
@ -1150,7 +1151,7 @@ void CloseEdit(HWND hWnd,int SI)
cell.row = r; cell.row = r;
cell.col = c; cell.col = c;
SendMessage(hWnd, BGM_SETCELLDATA, reinterpret_cast<WPARAM>(&cell), reinterpret_cast<LPARAM>(BGHS[SI].editstring)); SendMessage(hWnd, BGM_SETCELLDATA, reinterpret_cast<WPARAM>(&cell), reinterpret_cast<LPARAM>(BGHS[SI].editstring));
lstrcpy(BGHS[SI].editstring, TEXT("")); wcscpy_s(BGHS[SI].editstring, TEXT(""));
RefreshGrid(hWnd); RefreshGrid(hWnd);
BGHS[SI].EDITING = FALSE; BGHS[SI].EDITING = FALSE;
HideCaret(hWnd); HideCaret(hWnd);
@ -1222,7 +1223,7 @@ ATOM RegisterGridClass(HINSTANCE hInstance)
{ {
BGHS[j].gridmenu = 0; BGHS[j].gridmenu = 0;
BGHS[j].hlist1 = NULL; BGHS[j].hlist1 = NULL;
lstrcpy(BGHS[j].protect, TEXT("U")); wcscpy_s(BGHS[j].protect, TEXT("U"));
BGHS[j].rows = 100; BGHS[j].rows = 100;
BGHS[j].cols = 255; BGHS[j].cols = 255;
BGHS[j].homerow = 1; BGHS[j].homerow = 1;
@ -1261,7 +1262,7 @@ ATOM RegisterGridClass(HINSTANCE hInstance)
BGHS[j].hcolumnheadingfont = NULL; BGHS[j].hcolumnheadingfont = NULL;
BGHS[j].htitlefont = NULL; BGHS[j].htitlefont = NULL;
BGHS[j].INITIALCONTENT = FALSE; BGHS[j].INITIALCONTENT = FALSE;
lstrcpy(BGHS[j].editstring, TEXT("")); wcscpy_s(BGHS[j].editstring, TEXT(""));
for(int k = 0 ; k < MAX_COLS ; k++) for(int k = 0 ; k < MAX_COLS ; k++)
{ {
@ -1303,7 +1304,7 @@ int FindLongestLine(HDC hdc,TCHAR* text,SIZE* size)
TCHAR temptext[1000]; TCHAR temptext[1000];
TCHAR *p; TCHAR *p;
lstrcpy(temptext,text); wcscpy_s(temptext,text);
p = generic_strtok(temptext, TEXT("\n")); p = generic_strtok(temptext, TEXT("\n"));
while(p) while(p)
{ {
@ -1323,7 +1324,7 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
int wmId, wmEvent; int wmId, wmEvent;
PAINTSTRUCT ps; PAINTSTRUCT ps;
HDC hdc; HDC hdc;
const size_t bufferLen = 1000;
TCHAR buffer[bufferLen]; TCHAR buffer[bufferLen];
int SelfIndex; int SelfIndex;
int ReturnValue; int ReturnValue;
@ -1413,11 +1414,11 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
HFONT holdfont; HFONT holdfont;
if(lstrlen((TCHAR*)lParam)>300) 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 else
{ {
lstrcpy(BGHS[SelfIndex].title,(TCHAR*)lParam); wcscpy_s(BGHS[SelfIndex].title,(TCHAR*)lParam);
} }
gdc=GetDC(hWnd); gdc=GetDC(hWnd);
@ -1600,11 +1601,11 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case BGM_SETPROTECT: case BGM_SETPROTECT:
if((BOOL)wParam) if((BOOL)wParam)
{ {
lstrcpy(BGHS[SelfIndex].protect, TEXT("P")); wcscpy_s(BGHS[SelfIndex].protect, TEXT("P"));
} }
else else
{ {
lstrcpy(BGHS[SelfIndex].protect, TEXT("U")); wcscpy_s(BGHS[SelfIndex].protect, TEXT("U"));
} }
break; break;
@ -1731,7 +1732,7 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
int count=1; int count=1;
TCHAR tbuffer[255]; TCHAR tbuffer[255];
lstrcpy(tbuffer,(TCHAR*)lParam); wcscpy_s(tbuffer,(TCHAR*)lParam);
for(int j=0;j<(int)lstrlen(tbuffer);j++) for(int j=0;j<(int)lstrlen(tbuffer);j++)
{ {
if(tbuffer[j]=='\n'){count++;} if(tbuffer[j]=='\n'){count++;}
@ -1808,7 +1809,7 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
} }
int j,k,c; int j,k,c;
TCHAR tbuffer[1000]; TCHAR tbuffer[1000];
lstrcpy(tbuffer,buffer); wcscpy_s(tbuffer,buffer);
k=lstrlen(tbuffer); k=lstrlen(tbuffer);
c=0; c=0;
for(j=13;j<k;j++) for(j=13;j<k;j++)
@ -1817,11 +1818,11 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
c++; c++;
} }
buffer[c]=0x00; buffer[c]=0x00;
lstrcpy((TCHAR*)lParam,buffer); wcscpy_s((TCHAR*)lParam, bufferLen, buffer);
} }
else else
{ {
lstrcpy((TCHAR*)lParam, TEXT("")); wcscpy_s((TCHAR*)lParam, bufferLen, TEXT(""));
} }
break; break;
@ -2342,7 +2343,7 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if(BGHS[SelfIndex].EDITING) if(BGHS[SelfIndex].EDITING)
{ {
BGHS[SelfIndex].EDITING = FALSE; BGHS[SelfIndex].EDITING = FALSE;
lstrcpy(BGHS[SelfIndex].editstring, TEXT("")); wcscpy_s(BGHS[SelfIndex].editstring, TEXT(""));
HideCaret(hWnd); HideCaret(hWnd);
RefreshGrid(hWnd); RefreshGrid(hWnd);
NotifyEditEnd(hWnd,SelfIndex); NotifyEditEnd(hWnd,SelfIndex);
@ -2361,7 +2362,7 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if(BGHS[SelfIndex].EDITING) if(BGHS[SelfIndex].EDITING)
{ {
BGHS[SelfIndex].EDITING = FALSE; BGHS[SelfIndex].EDITING = FALSE;
lstrcpy(BGHS[SelfIndex].editstring, TEXT("")); wcscpy_s(BGHS[SelfIndex].editstring, TEXT(""));
HideCaret(hWnd); HideCaret(hWnd);
RefreshGrid(hWnd); RefreshGrid(hWnd);
NotifyEditEnd(hWnd,SelfIndex); NotifyEditEnd(hWnd,SelfIndex);
@ -2911,7 +2912,7 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
BGHS[SelfIndex].gridmenu = 0; BGHS[SelfIndex].gridmenu = 0;
BGHS[SelfIndex].hlist1 = NULL; BGHS[SelfIndex].hlist1 = NULL;
BGHS[SelfIndex].hfont = NULL; BGHS[SelfIndex].hfont = NULL;
lstrcpy(BGHS[SelfIndex].protect, TEXT("U")); wcscpy_s(BGHS[SelfIndex].protect, TEXT("U"));
BGHS[SelfIndex].rows = 100; BGHS[SelfIndex].rows = 100;
BGHS[SelfIndex].cols = 255; BGHS[SelfIndex].cols = 255;
BGHS[SelfIndex].homerow = 1; BGHS[SelfIndex].homerow = 1;
@ -3072,7 +3073,7 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
BGHS[BG_GridIndex].hfont = hfontbody; BGHS[BG_GridIndex].hfont = hfontbody;
BGHS[BG_GridIndex].htitlefont = hfonttitle; BGHS[BG_GridIndex].htitlefont = hfonttitle;
BGHS[BG_GridIndex].hcolumnheadingfont = hfontheader; BGHS[BG_GridIndex].hcolumnheadingfont = hfontheader;
lstrcpy(BGHS[BG_GridIndex].title,lpcs->lpszName); wcscpy_s(BGHS[BG_GridIndex].title,lpcs->lpszName);
SendMessage(hWnd, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(lpcs->lpszName)); SendMessage(hWnd, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(lpcs->lpszName));