s?wprintf family of functions has broken %s formatter output

Václav Zeman vhaisman@gmail.com
Mon Jun 11 12:37:00 GMT 2012


Hi.

I believe that I have discovered a bug in Cygwin's/Newlib's
implementation of s?wprintf() family of functions. They seem to print
only the first character in given string parameter. I am attaching a
test case and here is the broken output:

`-->  ./testvswprintf.exe
this works, 1, 2, 3...
but the following does not:
ret: 1
buf: >T<
>T<
ret: 4
wcout: >THIS IS A TEST<


The same code works well on both Ubuntu with GCC and on Windows with
Visual Studio 2010.

-- 
VZ
-------------- next part --------------
#include <cstdio>
#include <iostream>
#include <locale>
#include <clocale>

int
main ()
{
    // Setting locale has no effect on the problem.
    //std::locale::global (std::locale ());
    //std::setlocale (LC_ALL, "en_US.UTF-8");

    wchar_t buf[1024] = {};
    wchar_t const text[] = L"THIS IS A TEST";

    std::wprintf (L"this works, %d, %d, %d...\nbut the following does not:\n",
        1, 2, 3);

    int ret = std::swprintf (buf, sizeof (buf) / sizeof (buf[0]), L"%s",
        text);
    std::wcout << "ret: " << ret << "\n"
               << "buf: >" << buf << "<" << std::endl;

    ret = std::wprintf (L">%s<\n", text);
    std::fflush (stdout);
    std::wcout << "ret: " << ret << "\n";

    std::wcout << "wcout: >" << text << "<\n";
}
-------------- next part --------------
--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


More information about the Cygwin mailing list