🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Christopher Barber Fri, 01 Dec 1995 16:05
streambuf derivation error or bug in istream::getline?
#2799
Author: Christopher Barber
Date: Fri, 01 Dec 1995 16:05
23 lines
1661 bytes
I have derived a new class from streambuf and overloaded most
of the virtual protected members (overflow, underflow, xsgetn, xsputn, etc)
but do not touch the stream pointer methods (setg, gbump, setp, etc)
and as far as I understand the standard I don't need to.

The problem is that the implementation of istream::getline which I am using
(in gnu libio - I don't know the version offhand) accesses the gbeg, gnext,
gend pointers directly and ends up in an infinite loop when these pointers
are null (which is their default value).

I think this is a bug in the istream::getline implementation, but given
the complexity of the iostream classes am willing to consider the
possiblity that I have just misunderstood the spec.  Anyone, care to
comment?

- Chris
-- 
Christopher Barber        Software Engineer     BBN, Systems and Technologies
mailto:cbarber@bbn.com    http://malachite.bbn.com/~cbarber (within bbn)

[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: streambuf derivation error or bug in istream::getline?
#2851
Author: Bernd Eggink
Date: Mon, 04 Dec 1995 22:37
37 lines
2032 bytes
Christopher Barber (cbarber@bbn.com) wrote:
>  I have derived a new class from streambuf and overloaded most
>  of the virtual protected members (overflow, underflow, xsgetn, xsputn, etc)
>  but do not touch the stream pointer methods (setg, gbump, setp, etc)
>  and as far as I understand the standard I don't need to.

>  The problem is that the implementation of istream::getline which I am using
>  (in gnu libio - I don't know the version offhand) accesses the gbeg, gnext,
>  gend pointers directly and ends up in an infinite loop when these pointers
>  are null (which is their default value).

>  I think this is a bug in the istream::getline implementation, but given
>  the complexity of the iostream classes am willing to consider the
>  possiblity that I have just misunderstood the spec.  Anyone, care to
>  comment?

You MUST call setp() and segp() from within your functions overflow() and 
underflow() in order to set up the put/get area and reflect the fact 
that the put area is now empty and ready to be filled again, rsp. that the
get area has been filled from the source and characters may now be 
extracted.

	Bernd 

--
+----------------------------------+
|          Bernd Eggink            |
|    Rechenzentrum Uni Hamburg     |
| admin@rzaix13.rrz.uni-hamburg.de |
+----------------------------------+


---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: streambuf derivation error or bug in istream::getline?
#2887
Author: Christopher Barber
Date: Wed, 06 Dec 1995 22:26
34 lines
2435 bytes
>>>>> "CB" == Christopher Barber <cbarber@bbn.com>:
>>>>> "BE" == Bernd Eggink <admin@rzaix13.uni-hamburg.de>:

    CB> I have derived a new class from streambuf and overloaded most of the
    CB> virtual protected members (overflow, underflow, xsgetn, xsputn, etc)
    CB> but do not touch the stream pointer methods (setg, gbump, setp, etc)
    CB> and as far as I understand the standard I don't need to.

    BE> You MUST call setp() and segp() from within your functions
    BE> overflow() and underflow() in order to set up the put/get area and
    BE> reflect the fact that the put area is now empty and ready to be
    BE> filled again, rsp. that the get area has been filled from the
    BE> source and characters may now be extracted.

Creating a single character get area and pointing the get pointers fixed my
problem.  I can see why this is necessary for reads since a successful
return from underflow() essentially implies that gnext is valid.

However, in the case of writes, I see no reason that one is required to
call setp().  As far as I can see, there are no functions that guarantee
that there will be a position available in the put buffer.  So if you never
call setp(), the pointers will always be null and ostream routines will
just keep calling overflow() or xsputn().  Once again, have I overlooked
something in the standard?

- Chris

-- 
Christopher Barber        Software Engineer     BBN, Systems and Technologies
mailto:cbarber@bbn.com    http://malachite.bbn.com/~cbarber (within bbn)

[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads