[v3 PATCH 1/4] shcore: Implement a bunch of string conversion functions.

Gabriel Ivăncescu gabrielopcode at gmail.com
Thu Nov 29 05:15:18 CST 2018


On Thu, Nov 29, 2018 at 12:02 PM Dmitry Timoshkov <dmitry at baikal.ru> wrote:
>
> Nikolay Sivov <nsivov at codeweavers.com> wrote:
>
> > >> +DWORD WINAPI SHAnsiToAnsi(const char *src, char *dest, int dest_len)
> > >> +{
> > >> +    DWORD ret;
> > >> +
> > >> +    TRACE("(%s, %p, %d)\n", debugstr_a(src), dest, dest_len);
> > >> +
> > >> +    if (!src || !dest || dest_len <= 0)
> > >> +        return 0;
> > >> +
> > >> +    lstrcpynA(dest, src, dest_len);
> > >> +    ret = strlen(dest);
> > >> +
> > >> +    return src[ret] ? 0 : ret + 1;
> > >> +}
> > > lstrcpynA(dest, src, dest_len);
> > > ret = strlen(dest);
> > > if (ret) ret++;
> > > return ret;
> > It won't pass the tests.
>
> ... because of a typo.
>

Nikolay had a point here, though: this scans the string twice, but at
this point it probably doesn't matter.

On a related note: I'm wondering if we should have a custom Wine
strcpy helper (at least for wide version) for cases like these.

All it would do is return the string's end instead of the beginning
(which is completely useless), or return the amount copied, whatever.
Something useful.

Then we can easily do (ret - base) to get the length. strcpyW would be
implemented on top of it then.

Just an idea.



More information about the wine-devel mailing list