public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: peturr02@ru.is
To: gcc-gnats@gcc.gnu.org
Subject: libstdc++/9320: Incorrect usage of traits_type::int_type in stdio_filebuf
Date: Wed, 15 Jan 2003 10:26:00 -0000	[thread overview]
Message-ID: <20030115101933.18603.qmail@sources.redhat.com> (raw)


>Number:         9320
>Category:       libstdc++
>Synopsis:       Incorrect usage of traits_type::int_type in stdio_filebuf
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jan 15 02:26:01 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     peturr02@ru.is
>Release:        gcc-3.2.1
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
The constructors for __gnu_cxx::stdio_filebuf<> take an int_type parameter that is used to specify a buffer size.

However, stdio_filebuf<> has the same template parameters as basic_filebuf<>, so I assume that the same constraits are set on int_type, i.e. int_type is not required to be an integer type (or convertible to one).

In any case this is a bad example for any users wishing to derive their own classes from basic_streambuf<> or basic_filebuf<>.
>How-To-Repeat:
See attachment (should compile, but doesn't).
>Fix:
Use streamsize instead of int_type for the constructors.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="inttypebug.cc"
Content-Disposition: inline; filename="inttypebug.cc"

#include <ext/stdio_filebuf.h>

struct MyChar
{
	int val;
};

struct MyInt
{
	long val;
};

class MyState
{
};

class MyTraits
{
public:
	typedef MyChar char_type;
	typedef MyInt int_type;
	typedef std::streampos pos_type;
	typedef std::streamoff off_type;
	typedef MyState state_type;

	static void
	assign(char_type& __c1, const char_type& __c2);

	static bool
	eq(const char_type& __c1, const char_type& __c2);

	static bool
	lt(const char_type& __c1, const char_type& __c2);

	static int
	compare(const char_type* __s1, const char_type* __s2, size_t __n);

	static size_t
	length(const char_type* __s);

	static const char_type*
	find(const char_type* __s, size_t __n, const char_type& __a);

	static char_type*
	move(char_type* __s1, const char_type* __s2, size_t __n);

	static char_type*
	copy(char_type* __s1, const char_type* __s2, size_t __n);

	static char_type*
	assign(char_type* __s, size_t __n, char_type __a);

	static char_type
	to_char_type(const int_type& __c);

	static int_type
	to_int_type(const char_type& __c);

	static bool
	eq_int_type(const int_type& __c1, const int_type& __c2);

	static int_type
	eof();

	static int_type
	not_eof(const int_type& __c);
};

template class std::basic_streambuf<MyChar, MyTraits>;
template class std::basic_filebuf<MyChar, MyTraits>;
template class __gnu_cxx::stdio_filebuf<MyChar, MyTraits>;

int main()
{
	typedef __gnu_cxx::stdio_filebuf<MyChar, MyTraits> buf_type;
	buf_type buf1 (static_cast<FILE*>(0), std::ios_base::in);
	buf_type buf2 (0, std::ios_base::in, false, MyInt());
	return 0;
}


             reply	other threads:[~2003-01-15 10:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-15 10:26 peturr02 [this message]
2003-02-08 18:23 paolo
2003-02-13 12:20 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=20030115101933.18603.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).