David Laight wrote:
Be aware that strncyp() rarely DTRT, in particular:
- it doesn't guarantee to zero terminate the target
- it is required to zero fill the target buffer
Neither of these is usually desirable.
Well aware of both. Thanks. I'm routinely giving lectures about them
(
http://shemesh.biz/lectures).
Since the buffer is not zero terminated to begin with, 1 is not a
problem. Since the loop that strncpy replaces copied n bytes over from
the old buffer to the new one, neither is 2. This does impose the
theoretical problem that if the original string WAS zero terminated, and
the NULL was not the last WCHAR in the buffer, we change the semantics.
I doubt very much, however, that you will find a program that relies on
this. I don't even know what Windows does under the same circumstances.
Many systems have a strlcpy() function which does what
you want much
more often.
Well aware of that too. strncpy is really the most fitting here. Trust me.
OTOH is the target buffer can be too short with valid
data, they you
need to (typically) dynamically allocate a buffer.
Not applicable to GetCharacterPlacement.
David
Thanks.
Shachar
--
Shachar Shemesh
Open Source integration consultant
Home page & resume -
http://www.shemesh.biz/