Issue Details (XML | Word | Printable)

Key: STDCXX-435
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Critical Critical
Assignee: Martin Sebor
Reporter: Mark Brown
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
C++ Standard Library

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

Created: 04/Jun/07 04:55 AM   Updated: 17/Apr/08 02:33 PM
Return to search
Component/s: 22. Localization
Affects Version/s: 4.1.3, 4.1.4, 4.2.0
Fix Version/s: 4.2.1

Time Tracking:
Original Estimate: 8h
Original Estimate - 8h
Remaining Estimate: 2h
Time Spent - 6h Remaining Estimate - 2h
Time Spent: 6h
Time Spent - 6h Remaining Estimate - 2h

File Attachments:
  Size
Text File stdcxx-435.patch 2008-03-12 05:08 PM Eric Lemings 5 kB
Environment: gcc version 4.1.1 20070105 (Red Hat 4.1.1-51)
Issue Links:
dependent
 

Severity: Incorrect Behavior
Resolution Date: 12/Mar/08 11:03 PM


 Description  « Hide
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


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Martin Sebor made changes - 04/Jun/07 11:42 PM
Field Original Value New Value
Link This issue is depended upon by STDCXX-333 [ STDCXX-333 ]
Martin Sebor made changes - 04/Jun/07 11:48 PM
Assignee Martin Sebor [ sebor ]
Martin Sebor made changes - 04/Jun/07 11:49 PM
Fix Version/s 4.2 [ 12311945 ]
Priority Major [ 3 ] Critical [ 2 ]
Martin Sebor made changes - 10/Oct/07 07:04 PM
Severity Incorrect Behavior
Fix Version/s 4.2 [ 12311945 ]
Fix Version/s 4.2.1 [ 12312690 ]
Martin Sebor made changes - 21/Jan/08 06:00 PM
Remaining Estimate 8h [ 28800 ]
Original Estimate 8h [ 28800 ]
Martin Sebor made changes - 23/Jan/08 05:36 AM
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
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.

{code}

$ 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
Martin Sebor made changes - 23/Jan/08 05:38 AM
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.

{code}

$ 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
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.

{code}
$ 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
{code}
Eric Lemings made changes - 12/Mar/08 05:08 PM
Attachment stdcxx-435.patch [ 12377709 ]
Martin Sebor made changes - 12/Mar/08 10:10 PM
Status Open [ 1 ] In Progress [ 3 ]
Martin Sebor made changes - 12/Mar/08 11:03 PM
Resolution Fixed [ 1 ]
Status In Progress [ 3 ] Resolved [ 5 ]
Martin Sebor made changes - 17/Apr/08 02:31 PM
Affects Version/s 4.1.4 [ 12310693 ]
Affects Version/s 4.2.0 [ 12311945 ]
Martin Sebor made changes - 17/Apr/08 02:33 PM
Time Spent 6h [ 21600 ]
Remaining Estimate 8h [ 28800 ] 2h [ 7200 ]