This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libstdc++/9701: filebuf::sputc, in_avail incorrect


>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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]