Issue Details (XML | Word | Printable)

Key: STDCXX-333
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
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

[gcc 3.2.3/Linux] std::wfilebuf extracts more than 1 character from a 1 byte file

Created: 02/Feb/07 10:44 PM   Updated: 12/Mar/08 11:07 PM
Return to search
Component/s: 27. Input/Output
Affects Version/s: 4.1.3, 4.2.0
Fix Version/s: 4.2.1

Time Tracking:
Not Specified

Environment: gcc 3.2.3 on Linux
Issue Links:
dependent
 

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


 Description  « Hide
I get an an abort when I run the following program on Linux.
#include <cassert>
#include <fstream>
#include <iostream>

int main ()
{
    {
        std::filebuf fb;
        fb.open ("file", std::ios::out);
        fb.sputc ('a');
    }

    std::wfilebuf fb;
    fb.pubimbue (std::locale ("en_US.UTF-8"));
    fb.open ("file", std::ios::in);

    const int c[] = { fb.sbumpc (), fb.sgetc () };
    std::cout << c [0] << ' ' << c [1] << std::endl;

    assert (L'a' == c [0]);
    assert (std::wfilebuf::traits_type::eof () == c [1]);
}

test: test.cpp:21: int main(): Assertion `std::wfilebuf::traits_type::eof () == c [1]' failed.
Aborted


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Martin Sebor added a comment - 02/Feb/07 11:04 PM
How odd. I can reproduce this but only intermittently and with different results:

$ while [ $? -eq 0 ]; do ./t; done; true; while [ $? -eq 0 ]; do ./t; done
97 -1
97 -1
97 -1
97 -1
97 8
t: t.cpp:21: int main(): Assertion `std::wfilebuf::traits_type::eof () == c [1]' failed.
Aborted
97 -1
97 -1
97 -1
97 -1
97 -1
97 -1
97 104
: t.cpp:21: int main(): Assertion `std::wfilebuf::traits_type::eof () == c [1]' failed.
Aborted


Mark Brown added a comment - 19/Feb/07 08:17 PM
I tried to see if I could reproduce this problem on Cygwin. My version of Cygwin doesn't have any locales so I tried to generate the en_US.UTF-8 locale using the stdcxx localedef program. I got this error:

nls$ ../bin/localedef -c -f /home/mbrown/stdcxx/etc/nls/charmaps/UTF-8 -i /home/mbrown/stdcxx/etc/nls/src/en_US en_US.UTF-8
call to system LC_ALL=C /usr/bin/locale -a >/tmp/tdf4.0 2>/dev/null: No such file or directory
Hangup


Martin Sebor added a comment - 19/Feb/07 11:24 PM
This is specific to Linux (couldn't reproduce on Cygwin or Solaris).

Martin Sebor made changes - 19/Feb/07 11:24 PM
Field Original Value New Value
Priority Major [ 3 ] Minor [ 4 ]
Summary std::wfilebuf extracts more than 1 character from a 1 byte file Linux] std::wfilebuf extracts more than 1 character from a 1 byte file
Martin Sebor added a comment - 03/Jun/07 04:27 PM
Reproduced reliably with gcc 4.1.1 on Linux/x86_64.

Martin Sebor made changes - 04/Jun/07 11:42 PM
Assignee Martin Sebor [ sebor ]
Martin Sebor made changes - 04/Jun/07 11:42 PM
Link This issue depends upon STDCXX-435 [ STDCXX-435 ]
Martin Sebor made changes - 23/Aug/07 10:14 PM
Summary Linux] std::wfilebuf extracts more than 1 character from a 1 byte file [gcc 3.2.3/Linux] std::wfilebuf extracts more than 1 character from a 1 byte file
Martin Sebor added a comment - 10/Dec/07 07:10 AM
Set Severity to Incorrect Behavior.

Martin Sebor made changes - 10/Dec/07 07:10 AM
Severity Incorrect Behavior
Martin Sebor added a comment - 10/Dec/07 07:12 AM
I can't reproduce this with gcc 4.1.2 on Fedora Core 6, x86.

Martin Sebor added a comment - 15/Dec/07 12:56 AM
Couldn't reproduce with gcc 3.2.3-56 (tried 15s and 15S) on Red Hat EL 3 (Taroon Update 8) but reproduced it in a 15D buiold with gcc 4.1.0 on SuSE 10.0.

Next time though, before chasing this down, look at STDCXX-435 first!


Martin Sebor added a comment - 12/Mar/08 12:02 AM
Disabled formatting and set Affects and Fix Version/s.

Martin Sebor made changes - 12/Mar/08 12:02 AM
Description I get an an abort when I run the following program on Linux.

#include <cassert>
#include <fstream>
#include <iostream>

int main ()
{
    {
        std::filebuf fb;
        fb.open ("file", std::ios::out);
        fb.sputc ('a');
    }

    std::wfilebuf fb;
    fb.pubimbue (std::locale ("en_US.UTF-8"));
    fb.open ("file", std::ios::in);

    const int c[] = { fb.sbumpc (), fb.sgetc () };
    std::cout << c [0] << ' ' << c [1] << std::endl;

    assert (L'a' == c [0]);
    assert (std::wfilebuf::traits_type::eof () == c [1]);
}

test: test.cpp:21: int main(): Assertion `std::wfilebuf::traits_type::eof () == c [1]' failed.
Aborted
I get an an abort when I run the following program on Linux.

{noformat}
#include <cassert>
#include <fstream>
#include <iostream>

int main ()
{
    {
        std::filebuf fb;
        fb.open ("file", std::ios::out);
        fb.sputc ('a');
    }

    std::wfilebuf fb;
    fb.pubimbue (std::locale ("en_US.UTF-8"));
    fb.open ("file", std::ios::in);

    const int c[] = { fb.sbumpc (), fb.sgetc () };
    std::cout << c [0] << ' ' << c [1] << std::endl;

    assert (L'a' == c [0]);
    assert (std::wfilebuf::traits_type::eof () == c [1]);
}

test: test.cpp:21: int main(): Assertion `std::wfilebuf::traits_type::eof () == c [1]' failed.
Aborted
{noformat}
Affects Version/s 4.2.0 [ 12311945 ]
Fix Version/s 4.2.1 [ 12312690 ]
Martin Sebor added a comment - 12/Mar/08 11:07 PM
Fixed by resolving STDCXX-435.

Martin Sebor made changes - 12/Mar/08 11:07 PM
Resolution Fixed [ 1 ]
Status Open [ 1 ] Closed [ 6 ]