#51 istrstream not seekable

closed-remind
1
2007-07-15
2006-07-12
Eric Frias
No

When you call seekg() on an istrstream, it fails. In
the 4.5.3 release, and in many other STL
implementations, it behaves correctly.

In the old version, basic_istream::seekg(pos) called
basic_streambuf::pubseekpos(pos, ios_base::in). The
new version calls pubseekpos(pos), letting the second
argument (openmode) default to ios_base::in |
ios_base::out. Then in strstreambuf::seekoff(), the
ios_base::out flag causes the function to fail because
pptr() is NULL -- it triggers the middle term in the line:

if ((!do_get && !do_put) || (do_put && !pptr()) ||
!gptr())
return pos_type(off_type(-1));

The standard seems to support the new implementation of
basic_istream::seekg(), so I guess the error is in
strstreambuf::seekoff().

Test case follows
------

#include <strstream>
#include <iostream>

int main() {
std::istrstream a("Hello, world!\n");
std::cout << "First five chars of stream: ";
for (int i = 0; i < 5; ++i)
std::cout << (char)a.get();
std::cout << "\n";
std::cout << "tellg returns " << a.tellg() <<
", seeking back to start\n";
a.seekg(0);
std::cout << "tellg returns " << a.tellg() <<
"\n";
std::cout << "First five chars of stream after
seek: ";
for (int i = 0; i < 5; ++i)
std::cout << (char)a.get();
std::cout << "\n";
return 0;
}

/* produces the incorrect output:
First five chars of stream: Hello
tellg returns 5, seeking back to start
tellg returns -1
First five chars of stream after seek: ÿÿÿÿÿ
*/

Discussion

  • Petr Ovtchenkov

    Petr Ovtchenkov - 2006-08-11
    • assigned_to: nobody --> complement
     
  • Petr Ovtchenkov

    Petr Ovtchenkov - 2006-08-11
    • status: open --> open-wont-fix
     
  • Petr Ovtchenkov

    Petr Ovtchenkov - 2006-08-11
    • status: open-wont-fix --> open-remind
     
  • Petr Ovtchenkov

    Petr Ovtchenkov - 2006-09-01

    Logged In: YES
    user_id=615813

    Strstreams are really broken in STLport. But strstreams are
    obsolete, and even if ones was mentioned in D7.1--D7.4 of
    Standard, we have no wish to spent time with repair ones.

    But if you make general review if strstream code, add unit
    tests, and suggest general diff (aka patch) for one of
    STLport's mainstreams (5.0.2, 5.1.0, trunk) it would be
    nice.

    See also:
    https://sourceforge.net/tracker/index.php?func=detail&aid=1536503&group_id=146814&atid=766244

     
  • Petr Ovtchenkov

    Petr Ovtchenkov - 2006-09-01
    • priority: 5 --> 1
     
  • Petr Ovtchenkov

    Petr Ovtchenkov - 2007-07-15

    Logged In: YES
    user_id=615813
    Originator: NO

    Anybody who has interest to this obsolete interfaces may suggest patch and testcase.

     
  • Petr Ovtchenkov

    Petr Ovtchenkov - 2007-07-15
    • status: open-remind --> closed-remind
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks