• lstrcpyn documentation problem : string too long but call still succeed

    From R.Wieser@21:1/5 to All on Fri Nov 27 20:21:02 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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From R.Wieser@21:1/5 to All on Fri Nov 27 20:57:12 2020
    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*.

    A few tests show that it just copies what it can and terminates that with a NUL. But as that is not documented I should not depend on it and
    therefore still cannot use the function. :-(

    Oh well.

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From JJ@21:1/5 to R.Wieser on Sat Nov 28 09:13:08 2020
    On Fri, 27 Nov 2020 20:57:12 +0100, R.Wieser wrote:

    A few tests show that it just copies what it can and terminates that with a NUL.

    Then what do you need to happen when the buffer doesn't have enough space? Cause, that result is what a safe string copy process would do.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From R.Wieser@21:1/5 to All on Sat Nov 28 08:14:51 2020
    JJ,

    Then what do you need to happen when the buffer doesn't have enough space?

    Wrong question. What I /need/ is documented behaviour - whatever it does.

    Cause, that result is what a safe string copy process would do.

    I could as easily imagine that it would return an error. What good does a partial copied string do ? It might even be dangerous (in my case: causing the wrong file or folder to be accessed) ...

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From JJ@21:1/5 to R.Wieser on Sun Nov 29 13:17:44 2020
    On Sat, 28 Nov 2020 08:14:51 +0100, R.Wieser wrote:

    I could as easily imagine that it would return an error. What good does a partial copied string do ? It might even be dangerous (in my case: causing the wrong file or folder to be accessed) ...

    Some strings are copied just for displays where if the source is too long,
    the result will be truncated. Showing as much information as possible.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From R.Wieser@21:1/5 to All on Sun Nov 29 10:24:10 2020
    JJ,

    Some strings are copied just for displays where if the source is
    too long, the result will be truncated. Showing as much information
    as possible.

    Yeah, that was the only reason I could think of too. It makes me wonder
    why this, rather obvious user-related function, is part of kernel32 and not shell32 (or perhaps user32) though.

    And too bad that they removed(?) the explanation to what the function is actually ment for and does ... It would have cleared up the confusion in a heartbeat.

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)