This is the mail archive of the mailing list for the newlib project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[BUG] wprintf(L"%s", str) expects str to be wide


This works as expected in glibc:

#include <stdio.h>
wprintf(L"Hello, %s\n", "world");

However, the same thing does not work correctly in newlib. Instead, this works:

wprintf(L"Hello, %s\n", L"world");

I believe "%s" should always expect a narrow 8-bit string,
irrespective of the wideness of printf. "%ls" should be used for wide
strings. Newlib seems to interpret "%s" as wide for wide printfs,
which doesn't seem to be correct.

man wprintf:

       s      If no l  modifier  is  present:  The  const char *  argument  is
              expected  to be a pointer to an array of character type (pointer
              to a string) containing a multibyte character sequence beginning
              in  the initial shift state.  Characters from the array are conâ
              verted to wide characters (each by  a  call  to  the  mbrtowc(3)
              function  with  a conversion state starting in the initial state
              before the first byte).  The resulting wide characters are writâ
              ten  up to (but not including) the terminating null wide characâ
              ter. [..]

(This is with newlib 1.20.0)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]