msvcrt: Fixed buffer allocation in _getcwd/_wgetcwd.

This commit is contained in:
Alexandre Julliard 2007-07-27 12:17:58 +02:00
parent 8f0fb1e3e9
commit b2acafad44

View File

@ -419,11 +419,10 @@ char* CDECL _getcwd(char * buf, int size)
if (!buf)
{
if (size < 0)
return _strdup(dir);
return msvcrt_strndup(dir,size);
if (size <= dir_len) size = dir_len + 1;
if (!(buf = MSVCRT_malloc( size ))) return NULL;
}
if (dir_len >= size)
else if (dir_len >= size)
{
*MSVCRT__errno() = MSVCRT_ERANGE;
return NULL; /* buf too small */
@ -447,9 +446,8 @@ MSVCRT_wchar_t* CDECL _wgetcwd(MSVCRT_wchar_t * buf, int size)
if (!buf)
{
if (size < 0)
return _wcsdup(dir);
return msvcrt_wstrndup(dir,size);
if (size <= dir_len) size = dir_len + 1;
if (!(buf = MSVCRT_malloc( size * sizeof(WCHAR) ))) return NULL;
}
if (dir_len >= size)
{