Uploaded image for project: 'C++ Standard Library'
  1. C++ Standard Library
  2. STDCXX-435

[Linux] std::codecvt_byname("*.UTF-8").in() to_next greater than expected

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • 4.1.3, 4.1.4, 4.2.0
    • 4.2.1
    • 22. Localization
    • None
    • gcc version 4.1.1 20070105 (Red Hat 4.1.1-51)

    • Incorrect Behavior

    Description

      When compiled with gcc 4.1.1 on Linux the program below runs successfully to completion as it should. When compiled with stdcxx the facet returns a to_next value that is greater than the number of internal (wchar_t) characters actually produced by the conversion and consequently the program aborts.

      $ cat t.cpp && make t && ./t
      #include <cassert>
      #include <cwchar>
      #include <locale>
      
      int main ()
      {
          const std::locale utf8 ("en_US.UTF-8");
          typedef std::codecvt<wchar_t, char, std::mbstate_t> UTF8_Cvt;
      
          const UTF8_Cvt &cvt = std::use_facet<UTF8_Cvt>(utf8);
      
          const char src[] = "abc";
          wchar_t dst [2] = { L'\0' };
      
          const char* from_next;
      
          wchar_t* to_next;
      
          std::mbstate_t state = std::mbstate_t ();
      
          const std::codecvt_base::result res =
              cvt.in (state,
                      src, src + 1, from_next,
                      dst, dst + 2, to_next);
      
          assert (1 == from_next - src);
          assert (1 == to_next - dst);
          assert ('a' == dst [0]);
      }
      
      gcc -c -I/home/mbrown/stdcxx/include/ansi -D_RWSTDDEBUG    -I/home/mbrown/stdcxx/include -I/build/mbrown/stdcxx-gcc-4.1.1-11S/include -I/home/mbrown/stdcxx/examples/include  -pedantic -nostdinc++ -g   -W -Wall -Wcast-qual -Winline -Wshadow -Wwrite-strings -Wno-long-long -Wcast-align   t.cpp
      t.cpp: In function 'int main()':
      t.cpp:21: warning: unused variable 'res'
      gcc t.o -o t  -L/build/mbrown/stdcxx-gcc-4.1.1-11S/lib  -lstd11S -lsupc++ -lm 
      t: t.cpp:26: int main(): Assertion `1 == from_next - src' failed.
      Aborted
      

      Attachments

        1. stdcxx-435.patch
          5 kB
          Eric Lemings

        Issue Links

          Activity

            People

              sebor Martin Sebor
              mbrown Mark Brown
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 8h
                  8h
                  Remaining:
                  Time Spent - 6h Remaining Estimate - 2h
                  2h
                  Logged:
                  Time Spent - 6h Remaining Estimate - 2h
                  6h

                  Slack

                    Issue deployment