Igor,

Yes, it still crashes using istream and ostream to read and write.

Additionally, when running the program with valgrind for memory debugging there appear to be numerous memory read and write errors within the call to istream::read().

-- Dylan

On Sat, Feb 12, 2011 at 11:18 AM, Igor R <boost.lists@gmail.com> wrote:
> I've experienced problems using asio::streambuf and am hoping someone can
> tell me if I'm using the class incorrectly. When I run this example code it
> segfaults. Why?
>
> To make things more confusing, this code works on Windows (Visual Studio
> 2008), but does not work on Linux (with gcc 4.4.1).
>
> -- Dylan
>
> #include <boost/asio.hpp>
> using namespace std;
>
> int main()
> {
>         boost::asio::streambuf Stream;
>
>         // Put 4 bytes into the streambuf...
>         int SetValue = 0xaabbccdd;
>         Stream.sputn(reinterpret_cast<const char*>(&SetValue),
> sizeof(SetValue));
>
>         // Consume 3 of the bytes...
>         Stream.consume(3);
>         cout << Stream.size() << endl; // should output 1
>
>         // Get the last byte...
>         char GetValue;
>         // -------------------------- The next line segfaults the program
> --------------------------
>         Stream.sgetn(reinterpret_cast<char*>(&GetValue), sizeof(GetValue));
>         cout << Stream.size() << endl; // should output 0
>
>         return 0;
> }


If you write with:
       std::ostream(&Stream).write(reinterpret_cast<const
char*>(&SetValue), sizeof(SetValue));

and read with:
       std::istream(&Stream).read(reinterpret_cast<char*>(&SetValue),
sizeof(SetValue));

does it crash?
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users