libstdc++/9320: Incorrect usage of traits_type::int_type in stdio_filebuf

peturr02@ru.is peturr02@ru.is
Wed Jan 15 10:26:00 GMT 2003


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



More information about the Gcc-bugs mailing list