std_sstream.h (setbuf): Check __n >= 0.

2003-06-18  Paolo Carlini  <pcarlini@unitus.it>
	    Benjamin Kosnik  <bkoz@redhat.com>

	* include/std/std_sstream.h (setbuf): Check __n >= 0.
	* include/bits/fstream.tcc (setbuf): Tweak.

Co-Authored-By: Benjamin Kosnik <bkoz@redhat.com>

From-SVN: r68163
This commit is contained in:
Paolo Carlini 2003-06-18 21:13:18 +02:00 committed by Paolo Carlini
parent 4c526d0960
commit b82a33d2a9
3 changed files with 11 additions and 5 deletions

View File

@ -1,3 +1,9 @@
2003-06-18 Paolo Carlini <pcarlini@unitus.it>
Benjamin Kosnik <bkoz@redhat.com>
* include/std/std_sstream.h (setbuf): Check __n >= 0.
* include/bits/fstream.tcc (setbuf): Tweak.
2003-06-18 Paolo Carlini <pcarlini@unitus.it> 2003-06-18 Paolo Carlini <pcarlini@unitus.it>
* include/bits/sstream.tcc (seekoff): We can't seek beyond * include/bits/sstream.tcc (seekoff): We can't seek beyond

View File

@ -429,7 +429,7 @@ namespace std
{ {
if (!this->is_open() && __s == 0 && __n == 0) if (!this->is_open() && __s == 0 && __n == 0)
this->_M_buf_size = 1; this->_M_buf_size = 1;
else if (__s && __n >= 1) else if (__s && __n > 0)
{ {
// This is implementation-defined behavior, and assumes that // This is implementation-defined behavior, and assumes that
// an external char_type array of length __n exists and has // an external char_type array of length __n exists and has

View File

@ -208,12 +208,12 @@ namespace std
virtual __streambuf_type* virtual __streambuf_type*
setbuf(char_type* __s, streamsize __n) setbuf(char_type* __s, streamsize __n)
{ {
if (__s && __n) if (__s && __n >= 0)
{ {
// This is implementation-defined behavior, and assumes // This is implementation-defined behavior, and assumes
// that an external char_type array of length (__s + __n) // that an external char_type array of length __n exists
// exists and has been pre-allocated. If this is not the // and has been pre-allocated. If this is not the case,
// case, things will quickly blow up. // things will quickly blow up.
// Step 1: Destroy the current internal array. // Step 1: Destroy the current internal array.
_M_string = __string_type(__s, __n); _M_string = __string_type(__s, __n);