Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

streambuf->sungetc() segv

807575Jan 31 2006 — edited Jan 31 2006
Hi

I get segmentation fault with the following example using
CC: Sun C++ 5.8 2005/10/13
CC: Sun C++ 5.6 Patch 117549-04 2005/10/11

Should I really get segv and what can I use as workaround ( instead of sungetc ) ?

CC test.cpp && ./a.out
read bytes 9
sungetc 10

CC test.cpp -library=stlport4 && ./a.out
read bytes 9
Segmentation Fault(coredump)

file: text
QWERTYUI

file: test.cpp
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
        char buffer[256];

        ifstream ifs( "text" );

        if( ifs )
        {
                streambuf * sbuf = ifs.rdbuf();

                int bytes = sbuf->sgetn( buffer, sizeof( buffer ) );

                cout << "read bytes " << bytes << endl;

                int status = sbuf->sungetc();

                cout << "sungetc    " << status << endl;

                ifs.close();
        }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 28 2006
Added on Jan 31 2006
2 comments
185 views