public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: peturr02@ru.is
To: gcc-gnats@gcc.gnu.org
Subject: libstdc++/9701: filebuf::sputc, in_avail incorrect
Date: Fri, 14 Feb 2003 07:56:00 -0000	[thread overview]
Message-ID: <20030214075356.18449.qmail@sources.redhat.com> (raw)


>Number:         9701
>Category:       libstdc++
>Synopsis:       filebuf::sputc, in_avail incorrect
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Feb 14 07:56:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     peturr02@ru.is
>Release:        gcc-3.2.1
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
filebuf::sputc does not always call overflow when pptr() >= epptr().
filebuf::in_avail does not return egptr() - gptr() if it follows sputbackc.
>How-To-Repeat:
See attachment.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="filebufbug.cc"
Content-Disposition: inline; filename="filebufbug.cc"

#include <fstream>
#include <cassert>

using namespace std;

bool called = false;

class dfbuf : public filebuf
{
public:
  const char* pub_epptr() const
  {
    return epptr();
  }

  const char* pub_egptr() const
  {
    return egptr();
  }

  const char* pub_gptr() const
  {
    return gptr();
  }

  const char* pub_pptr() const
  {
    return pptr();
  }

  virtual int overflow(int c)
  {
    called = true;
    return filebuf::overflow(c);
  }
};

void test01()
{
  dfbuf df1;
  df1.open("tmp", ios_base::in | ios_base::out | ios_base::trunc);

  // File empty -> no get buffer available
  assert(df1.pub_gptr() == df1.pub_egptr());

  assert(df1.pub_pptr() == df1.pub_epptr());
  called = false;
  df1.sputc('a');
  assert(called);
}

void test02()
{
  dfbuf df2;
  df2.open("tmp", ios_base::in | ios_base::out | ios_base::trunc);

  df2.sputn("0123456789", 10);

  df2.pubseekoff(0, ios_base::beg);
  df2.sbumpc();
  
  df2.sputbackc('a');
  assert(df2.pub_gptr() < df2.pub_egptr());
  assert(df2.in_avail() == df2.pub_egptr() - df2.pub_gptr());
}

int main()
{
  //test01();
  test02();

  return 0;
}


             reply	other threads:[~2003-02-14  7:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-14  7:56 peturr02 [this message]
2003-02-23 17:17 paolo
2003-05-18  8:09 paolo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030214075356.18449.qmail@sources.redhat.com \
    --to=peturr02@ru.is \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).