public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: libstdc++/10094: Regression: wfilebuf::showmanyc return value too high.
@ 2003-03-22 15:18 paolo
  0 siblings, 0 replies; 5+ messages in thread
From: paolo @ 2003-03-22 15:18 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, peturr02

Synopsis: Regression: wfilebuf::showmanyc return value too high.

State-Changed-From-To: analyzed->closed
State-Changed-By: paolo
State-Changed-When: Sat Mar 22 15:18:43 2003
State-Changed-Why:
    Defective testcase.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10094


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: libstdc++/10094: Regression: wfilebuf::showmanyc return value too high.
@ 2003-03-16 11:26 Pétur Runólfsson
  0 siblings, 0 replies; 5+ messages in thread
From: Pétur Runólfsson @ 2003-03-16 11:26 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR libstdc++/10094; it has been noted by GNATS.

From: =?iso-8859-1?Q?P=E9tur_Run=F3lfsson?= <peturr02@ru.is>
To: =?iso-8859-1?Q?P=E9tur_Run=F3lfsson?= <peturr02@ru.is>,
	<paolo@gcc.gnu.org>,
	<gcc-bugs@gcc.gnu.org>,
	<nobody@gcc.gnu.org>,
	<gcc-gnats@gcc.gnu.org>
Cc:  
Subject: RE: libstdc++/10094: Regression: wfilebuf::showmanyc return value too high.
Date: Sun, 16 Mar 2003 11:17:48 -0000

 > > Synopsis: Regression: wfilebuf::showmanyc return value too high.
 > >=20
 > > State-Changed-From-To: open->analyzed
 > > State-Changed-By: paolo
 > > State-Changed-When: Sat Mar 15 13:32:25 2003
 > > State-Changed-Why:
 > >     Ok, however the (interesting) analysis is science fiction
 > >     ;-) : the new showmanyc it's still in review!!
 >=20
 > Indeed :-) seems there is a bug in the old implementation...
 
 Or rather, there is bug in the testcase. My bad :-(
 
 Sorry about this confusion
 Petur


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: libstdc++/10094: Regression: wfilebuf::showmanyc return value too high.
@ 2003-03-15 14:56 Pétur Runólfsson
  0 siblings, 0 replies; 5+ messages in thread
From: Pétur Runólfsson @ 2003-03-15 14:56 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR libstdc++/10094; it has been noted by GNATS.

From: =?iso-8859-1?Q?P=E9tur_Run=F3lfsson?= <peturr02@ru.is>
To: <paolo@gcc.gnu.org>,
	<gcc-bugs@gcc.gnu.org>,
	<nobody@gcc.gnu.org>,
	=?iso-8859-1?Q?P=E9tur_Run=F3lfsson?= <peturr02@ru.is>,
	<gcc-gnats@gcc.gnu.org>
Cc:  
Subject: RE: libstdc++/10094: Regression: wfilebuf::showmanyc return value too high.
Date: Sat, 15 Mar 2003 14:51:58 -0000

 > Synopsis: Regression: wfilebuf::showmanyc return value too high.
 >=20
 > State-Changed-From-To: open->analyzed
 > State-Changed-By: paolo
 > State-Changed-When: Sat Mar 15 13:32:25 2003
 > State-Changed-Why:
 >     Ok, however the (interesting) analysis is science fiction
 >     ;-) : the new showmanyc it's still in review!!
 
 Indeed :-) seems there is a bug in the old implementation...
 
 >     Anyway, what to do here? Which kind of estimate is not
 >     affected by the problem?!?
 
 Obviously, if codecvt::always_noconv() =3D=3D true, this isn't a
 problem. However, it seems unreasonable to require showmanyc to
 read and convert the characters before returning.
 
 I think the real problem here is that underflow() shouldn't
 return eof() when codecvt::in() fails. Consider this example:
 
 wifstream stream;
 stream.imbue(locale("se_NO.UTF-8"));
 // foo begins with the bytes \xc0\xff followed by lots of
 // stuff.
 stream.open("foo");
 
 int n;
 stream >> n;
 wifstream::iostate s =3D stream.rdstate();
 
 What is the value of s?
 
 wistream::operator>>(int&) calls rdbuf()->sbumpc() or sgetc(),
 which call underflow(). underflow() reads bytes from the file,
 attempts to convert with codecvt::in(), which fails.
 
 Currently, this causes underflow() to return eof(), which
 causes sgetc() to return eof(), which means that s is set to
 eofbit | failbit. I see nothing in the standard that requires
 this behaviour (*), however, eofbit is described so:
 
   eofbit: indicates that an input operation reached the end
           of an input sequence; =20
 
 This appears to mean that eofbit() should *not* be set when
 underflow() has a conversion error, however, badbit seems
 just right:
 
   badbit: indicates a loss of integrity in an input or output
           sequence (such as an irrecoverable read error from
           a file);
 
 So it seems that !(s & eofbit) && (s & badbit) should hold.
 The only reasonable way to achieve this is for underflow() to
 throw an exception (probably of type ios_base::failure).
 
 Back to showmanyc:
 
 If underflow() throws an exception on conversion errors, the
 proposed implementation of showmanyc is OK, since showmanyc
 only guarantees that underflow() doesn't return eof() until
 the specified number of characters has been read, there is
 a footnote that indicates that it is OK for underflow() to
 throw an exception anytime.
 
 Petur
 
 (*) Indeed, I don't see anything about what underflow()
 should do when codecvt::in() fails. If you know of anything
 please let me know :-)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: libstdc++/10094: Regression: wfilebuf::showmanyc return value too high.
@ 2003-03-15 13:32 paolo
  0 siblings, 0 replies; 5+ messages in thread
From: paolo @ 2003-03-15 13:32 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, peturr02

Synopsis: Regression: wfilebuf::showmanyc return value too high.

State-Changed-From-To: open->analyzed
State-Changed-By: paolo
State-Changed-When: Sat Mar 15 13:32:25 2003
State-Changed-Why:
    Ok, however the (interesting) analysis is science fiction
    ;-) : the new showmanyc it's still in review!!
    Anyway, what to do here? Which kind of estimate is not
    affected by the problem?!?

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10094


^ permalink raw reply	[flat|nested] 5+ messages in thread

* libstdc++/10094: Regression: wfilebuf::showmanyc return value too high.
@ 2003-03-15 10:46 peturr02
  0 siblings, 0 replies; 5+ messages in thread
From: peturr02 @ 2003-03-15 10:46 UTC (permalink / raw)
  To: gcc-gnats


>Number:         10094
>Category:       libstdc++
>Synopsis:       Regression: wfilebuf::showmanyc return value too high.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Mar 15 10:46:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     peturr02@ru.is
>Release:        gcc mainline from 20030312
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
The return value of wfilebuf::showmanyc is only calculated from codecvt::max_length and the number of bytes in the file. This means that when the file contains illegal multibyte sequences, showmanyc promises more characters than underflow can deliver.
>How-To-Repeat:
See attachment.
>Fix:

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

#include <fstream>
#include <locale>

#undef NDEBUG
#include <cassert>

int main()
{
	using namespace std;

	const char* name = "tmp";
	const char* strlit = "\xc0\xff For What You Dream Of";
	
	filebuf fbout;
	fbout.open(name, ios_base::out | ios_base::trunc);

	for (int i = 0; i < BUFSIZ; ++i)
		fbout.sputc('a');

	fbout.sputn(strlit, strlen(strlit));
	fbout.close();

	wfilebuf fbin;
	fbin.pubimbue(locale("se_NO.UTF-8"));
	fbin.open(name, ios_base::in);

	streamsize n = fbin.in_avail();
	while (n > 0)
	{
		if (--n == 0)
			n = fbin.in_avail();

		wfilebuf::int_type c = fbin.sbumpc();
		assert(c != wfilebuf::traits_type::eof());
	}

	fbin.close();

	return 0;
}


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-03-22 15:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-22 15:18 libstdc++/10094: Regression: wfilebuf::showmanyc return value too high paolo
  -- strict thread matches above, loose matches on Subject: below --
2003-03-16 11:26 Pétur Runólfsson
2003-03-15 14:56 Pétur Runólfsson
2003-03-15 13:32 paolo
2003-03-15 10:46 peturr02

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).