lstrcpyn documentation problem : string too long but call still succeedes?

Giganews Newsgroups
Subject: lstrcpyn documentation problem : string too long but call still succeedes?
Posted by:  R.Wieser (addre…@not.available)
Date: Fri, 27 Nov 2020

Hello all,

I need to copy an ANSI string from a source into a buffer with a fixed
length.  That looks like a job for "lstrcpynA".  Easy-Peasy, right ?

There is only a tiny issue with it : For some reason its able to accept a
string that is too long to place in the target buffer, *but still succeed*.

The problem (to me) is that the MSDN docucumentation to the call [1] do not
even /hint/ at how I'm supposed to detect such a succeeded-but-failed
situation.  :-(

[1]
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-lstrcpyna

Does anyone know whay the succeeded-but-failed result look like ?

Regards,
Rudy Wieser

P.s.
I've seen the page state that I should not use that function, but instead
something like StringCchCopy.  The problem with that is that they "forgot"
to mention which DLL its part of ... if its actually a DLL function to begin
with.

Replies