Program to list all files in a directory (recursively)
Version 1 works perfectly. Version 2 crashes with STACK OVERFLOW.
Version 1: It is designed for MULTIBYTE character set. It makes use of the stat() system call.
Version 2: It is designed for Unicode. Moreover, stat() had some problems with old files and so I replaced it with GetFileAttributes(). Also, I wanted to support long paths so I append the path with \\?\ (file:///?\).
Can someone please have a look at the code and tell me why does Version 2 crash ?
(I tried copy pasting the code here from my IDE, however the formatting got really messed up, so I am attachting the 2 versions as .c files. I hope that does not prevent you guys from having a look at it :--)
Now another problem in Version 2: you will see that I am dynamically allocating path. malloc for this fails, I have no idea why. Does it fail for you too ? (for the purpose of testing, I used an array of wchar_t)
I had:
LPTSTR path = NULL;
path = (LPTSTR)malloc(pathlen);
which I changed to
wchar_t path[32767];
I will really appreciate if someone can tell me whats going on. Why do I get a stack overflow and a failed malloc for Version 2.
The stack overflow occurs when the depth of a directory is around 12 or 13.
Thanks !!!

