sprintfW formatting in lib\wine\string.c

Ann & Jason Edmeades us at edmeades.me.uk
Thu May 10 14:46:13 CDT 2007

Whilst trying to convert cmd to Unicode, I've stumbled across a problem
which I either need to work around or fix, and I am not sure which. 

WCHAR h[] = {'h','e','l','l','o','\0'};
WCHAR fmt[] = {':', '%', '1', '0','s',':','\0'};
char test[255];
WCHAR result[255];
sprintf(test, "'%10s'", "hello");
sprintfW(result, fmt, h);
WINE_FIXME("%s vs %s\n", test, wine_dbgstr_w(result));

fixme:cmd:WCMD_list_directory '     hello' vs L":hello:"

sprintf of %10s means right justified field of 10 characters
sprintfW of %10s gives left justified field of n characters 

(I haven't tried if the string is > 10, as I don't care...)

Basically, the format strings in cmd rely on the padding behaviour. Is this
a bug in sprintfW which needs fixing, or should I work around it?

Unfortunately, looking in the code to lib\wine\string.c, it just copies the
field and ignores justification or min/max width precisions for strings, and
as it is used all over the place there's also a concern of what would be
changed by fixing it.

Any suggestions for a workable alternative?


More information about the wine-devel mailing list