[Bug localedata/14257] New: setlocale(LC_CTYPE, NULL) causes undesired side effects

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug localedata/14257] New: setlocale(LC_CTYPE, NULL) causes undesired side effects

glaubitz at physik dot fu-berlin.de
http://sourceware.org/bugzilla/show_bug.cgi?id=14257

             Bug #: 14257
           Summary: setlocale(LC_CTYPE, NULL) causes undesired side
                    effects
           Product: glibc
           Version: 2.14
            Status: NEW
          Severity: normal
          Priority: P2
         Component: localedata
        AssignedTo: [hidden email]
        ReportedBy: [hidden email]
                CC: [hidden email]
    Classification: Unclassified


I have written following program to reproduce side effect :

#include <stdio.h>
#include <wchar.h>
#include <locale.h>

int main()
{
    setlocale(LC_ALL,"");


    //This will cause side effect
    const char * c = setlocale(LC_CTYPE, NULL);
    printf("%s\n", c);


    while (!feof(stdin))
    {
        wint_t t = fgetwc(stdin);
        wchar_t t1 = static_cast<wchar_t>(t);

        putwc(t1, stdout);
    }
}

When I try to input unicode characters I get garbage characters in output.

[situ@juggernaut bugs]$  ./a.out
测试
K�


If I remove call to setlocale(LC_CTYPE, NULL) output is fine.

[situ@juggernaut bugs]$  ./a.out
测试
测试

--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug localedata/14257] setlocale(LC_CTYPE, NULL) causes undesired side effects

glaubitz at physik dot fu-berlin.de
http://sourceware.org/bugzilla/show_bug.cgi?id=14257

Andreas Schwab <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID

--- Comment #1 from Andreas Schwab <[hidden email]> 2012-06-16 17:47:41 UTC ---
This has nothing to do with setlocale.  You are mixing char with wide char I/O
on the same stream (printf vs. putwc).  The first output makes the orientation
permanent until the stream is closed.

--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.