I'm not positive, but I think ostrstream should prevent buffer overflows.
ostrstream is derived from basic_ostream and initializes the base class with a strstreambuf. strstrambuf is derived from basic_streambuf. Section 27.5 of the standard specifies stream buffers in nine pages. I didn't read it all, but it looks like a stream buffer is responsible for not writing beyond its controlled sequence. Note that although ostrstream is deprecated, the base classes basic_ostream and basic_streambuf are not.
Main Topics
Browse All Topics





by: Infinity08Posted on 2009-08-17 at 15:46:48ID: 25119046
I have quickly checked the standard, but couldn't find a guarantee that buffer overflows are prevented.
That said, trying it out, shows that at least the gcc compiler prevents buffer overflows (ie. it only writes 5 characters into the buffer).
I have never actually needed to use the deprecated strstream classes though, so take my advice as purely theoretical, and based on a test for one specific compiler :)