lstrcpyn is documented to always return a NUL terminated string

svn path=/trunk/; revision=7994
This commit is contained in:
Gé van Geldorp 2004-02-02 15:50:16 +00:00
parent 90fd161f1e
commit 08b2e62907

View file

@ -51,21 +51,28 @@ lstrcpynA(
) )
{ {
/* Can't use strncpy, because strncpy will fill unused bytes in /* Can't use strncpy, because strncpy will fill unused bytes in
lpString1 with NUL bytes while lstrcpynA doesn't */ lpString1 with NUL bytes while lstrcpynA doesn't. Also lstrcpynA
guarantees NUL termination while strncpy doesn't */
if (0 != iMaxLength) if (1 < iMaxLength)
{ {
char *d = lpString1; char *d = lpString1;
const char *s = lpString2; const char *s = lpString2;
do do
{ {
if (0 == (*d++ = *s++)) if ('\0' == (*d++ = *s++))
{ {
break; break;
} }
} }
while(0 != --iMaxLength); while(1 != --iMaxLength);
*d = '\0';
}
else if (1 == iMaxLength)
{
/* Only space for the terminator */
*lpString1 = '\0';
} }
return lpString1; return lpString1;
@ -153,21 +160,28 @@ lstrcpynW(
) )
{ {
/* Can't use wcsncpy, because wcsncpy will fill unused bytes in /* Can't use wcsncpy, because wcsncpy will fill unused bytes in
lpString1 with NUL bytes while lstrcpynW doesn't */ lpString1 with NUL bytes while lstrcpynW doesn't Also lstrcpynW
guarantees NUL termination while wcsncpy doesn't */
if (0 != iMaxLength) if (1 < iMaxLength)
{ {
WCHAR *d = lpString1; WCHAR *d = lpString1;
const WCHAR *s = lpString2; const WCHAR *s = lpString2;
do do
{ {
if (0 == (*d++ = *s++)) if (L'\0' == (*d++ = *s++))
{ {
break; break;
} }
} }
while(0 != --iMaxLength); while(1 != --iMaxLength);
*d = L'\0';
}
else if (1 == iMaxLength)
{
/* Only space for the terminator */
*lpString1 = L'\0';
} }
return lpString1; return lpString1;