diff --git a/memory/string.c b/memory/string.c index 41addcfd784..7ef573e2220 100644 --- a/memory/string.c +++ b/memory/string.c @@ -437,12 +437,18 @@ LPWSTR WINAPI lstrcpynAtoW( LPWSTR dst, LPCSTR src, INT n ) * lstrcpynWtoA (Not a Windows API) * Note: this function differs from the UNIX strncpy, it _always_ writes * a terminating \0 + * + * The terminating zero should be written at the end of the string, not + * the end of the buffer, as some programs specify the wrong size for + * the buffer (eg. winnt's sol.exe) */ LPSTR WINAPI lstrcpynWtoA( LPSTR dst, LPCWSTR src, INT n ) { if (--n >= 0) { - CRTDLL_wcstombs( dst, src, n ); + n = CRTDLL_wcstombs( dst, src, n ); + if(n<0) + n=0; dst[n] = 0; } return dst;