I’ve been trying to figure out why this is giving me a stack overflow for hours, probably something simple that I just am missing, it was working earlier until I messed with it to try to clean it up. Anyways some fresh eyes would be greatly appreciated.
int scan(LPSTR szPath, LPSTR pattern) {
WIN32_FIND_DATA WFD;
HANDLE hSearch;
CHAR szFullPath [MAX_PATH+1] = "";
PVOID OldValue = NULL;
if( Wow64DisableWow64FsRedirection(&OldValue) )
{
PathCombine(szFullPath, szPath, "*");
hSearch = FindFirstFile(szFullPath, &WFD);
if ( hSearch != INVALID_HANDLE_VALUE ) {
while(FindNextFile(hSearch,&WFD)) {
if(strcmp(WFD.cFileName,"..") || strcmp(WFD.cFileName,".")){
FindNextFile(hSearch,&WFD);
}
if(WFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
PathCombine(szFullPath, szPath, WFD.cFileName);
scan(szFullPath, pattern);
}
}
FindClose(hSearch);
}
PathCombine(szFullPath, szPath, pattern);
hSearch = FindFirstFile(szFullPath, &WFD);
if( hSearch != INVALID_HANDLE_VALUE ) {
while( FindNextFile(hSearch, &WFD) ) {
if(!(WFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
PathCombine(szFullPath, szPath, WFD.cFileName);
int index = SendDlgItemMessage(ghWnd, IDLIST, LB_ADDSTRING, 0, (LPARAM)szFullPath);
}
}
FindClose(hSearch);
if ( FALSE == Wow64RevertWow64FsRedirection(OldValue) )
{
return 0;
}
}
return 0;
}
I think the problem is here:
Add a “continue” statement to fix the issue. The check for “.” and “..” is good. The problem is the code breaks if they are adjacent.
Edit: Specifically, add “continue” after FindNextFile in this code block.