Errors in streambuf.h

rmccrac@bellsouth.net rmccrac@bellsouth.net
Mon Nov 20 11:08:00 GMT 2000


This is not to report a bug in GCC itself, but some apparent
mistakes in one of the C++ headers included with 2.95.2.

Originator
----------
Bob McCracken	<rmccrac@bellsouth.net>

Organization
------------
None

Confidential
------------
No

Synopsis
--------
There are what seem to be errors in g++-3/streambuf.h.

Severity
--------
Non-critical

Priority
--------
Medium

Category
--------
c++

Class
-----
sw-bug

Release
-------
Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/specs
gcc version 2.95.2 19991024 (release)

Environment
-----------
Linux 2.2.17

Description
-----------
In /usr/include/g++-3/streambuf.h, lines 361-364:

    streampos pubseekoff(streamoff o, _seek_dir d, int mode=ios::in|ios::out)
      { return _IO_seekoff (this, o, d, mode); }
    streampos pubseekpos(streampos pos, int mode = ios::in|ios::out)
      { return _IO_seekpos (this, pos, mode); }

The actual return values of these functions do not match their declared
return types. They declare a return of "streampos", which is a structure
(same as _G_fpos64_t, defined in _G_config.h), but actually return the
return values of _IO_seekoff() and _IO_seekpos(), both of which return a
_G_off64_t, which is the same as __off64_t, which is a long long.

Also, the 2nd parameter to _IO_seekpos() in pubseekpos() is given wrongly
as "pos", which is a struct streampos. The parameter should really be of
type __off64_t.

Here is an example of g++ error messages from a failed compile:

/usr/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/streambuf.h: In method `struct streampos streambuf::pubseekoff(long long int, ios::seek_dir, int = 3)':
/usr/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/streambuf.h:362: conversion from `__off64_t' to non-scalar type `streampos' requested
/usr/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/streambuf.h: In method `struct streampos streambuf::pubseekpos(_G_fpos64_t, int = 3)':
/usr/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/streambuf.h:364: `struct streampos' used where a `long long int' was expected
/usr/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/streambuf.h:364: warning: control reaches end of non-void function `streambuf::pubseekpos(_G_fpos64_t, int)'

How-To-Repeat
-------------
Simply #include <streambuf.h>.

Fix
---
Here are my corrections to lines 361-364:

    _IO_off64_t pubseekoff(streamoff o, _seek_dir d, int mode=ios::in|ios::out)
      { return _IO_seekoff (this, o, d, mode); }
    _IO_off64_t pubseekpos(streampos pos, int mode = ios::in|ios::out)
      { return _IO_seekpos (this, pos.__pos, mode); }
				  ^^^^^^^^^
This "worked" for me, but the code I was compiling did not actually call
either of these functions, so I don't know if these changes will break
something. In particular, I'm concerned about my assumption that the
"streampos pos" parameter is correct in pubseekpos(). Callers of this
function, if they exist, might actually be using a scalar "pos", in
which case passing pos.__pos to _IO_seekpos() would be quite wrong.

Thanks,

	Bob McCracken



More information about the Gcc-bugs mailing list