Avoid the use of wcscat_s() since it's unavailable under Win XP.

Code around it by using `wcsncpy()` and `wcscat()` combined with a
manual length check. This should be enough to make YQ2 working on Win
XP again.  Please note, that we don't support any Windows older than
10. However we still try to avoid breaking them.

Based on an idea by @ carlo-bramini, closes #994.
This commit is contained in:
Yamagi 2023-04-22 16:40:32 +02:00
parent f67b65c00a
commit df845e0f67

View file

@ -577,10 +577,17 @@ Sys_RemoveDir(const char *path)
WCHAR wpathwithfilename[MAX_OSPATH] = {0};
WIN32_FIND_DATAW fd;
MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, MAX_OSPATH);
if (MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, MAX_OSPATH) >= MAX_QPATH)
{
/* This is hopefully never reached, because in a good
world path has a maximum length of MAX_QPATH. Since
we can't use wcscat_s() below because it would break
compat with Win XP, nevertheless do this check. */
return;
}
wcscat_s(wpathwithwildcard, MAX_OSPATH, wpath);
wcscat_s(wpathwithwildcard, MAX_OSPATH, L"\\*.*");
wcsncpy(wpathwithwildcard, wpath, MAX_OSPATH);
wcscat(wpathwithwildcard, L"\\*.*");
HANDLE hFind = FindFirstFileW(wpathwithwildcard, &fd);
if (hFind != INVALID_HANDLE_VALUE)