Commit b9701bffe647e16fde3d5ede3066a4a6e9997135
- Diff rendering mode:
- inline
- side by side
etc/ChangeLog-5.1
(9 / 0)
|   | |||
| 1 | 2007-11-12 Petr Ovtchenkov <complement@users.sourceforge.net> | ||
| 2 | |||
| 3 | * test/unit/fstream_test.cpp: testcase for bug #1830513; | ||
| 4 | __read_unbuffered wrongly process valid streamsize 0; | ||
| 5 | [was derived from original report of Anton Samokhvalov and Oleg Obolenskiy] | ||
| 6 | |||
| 7 | * stlport/stl/_istream.c: fix for bug #1830513 above; | ||
| 8 | check boundary condition in the beginning of loop. | ||
| 9 | |||
| 1 | 10 | 2007-10-21 Francois Dumont <dums@users.sourceforge.net> | |
| 2 | 11 | ||
| 3 | 12 | * src/allocators.cpp: Add missing const_cast in lock free |
stlport/stl/_istream.c
(12 / 13)
|   | |||
| 578 | 578 | streamsize _Num, _CharT* __s, | |
| 579 | 579 | _Is_Delim __is_delim, | |
| 580 | 580 | bool __extract_delim, bool __append_null, | |
| 581 | bool __is_getline) { | ||
| 581 | bool __is_getline) | ||
| 582 | { | ||
| 582 | 583 | streamsize __n = 0; | |
| 583 | 584 | ios_base::iostate __status = 0; | |
| 584 | 585 | ||
| … | … | ||
| 587 | 587 | // The operations that can potentially throw are sbumpc, snextc, and sgetc. | |
| 588 | 588 | _STLP_TRY { | |
| 589 | 589 | for (;;) { | |
| 590 | if (__n == _Num) { | ||
| 591 | if (__is_getline) // didn't find delimiter as one of the _Num chars | ||
| 592 | __status |= ios_base::failbit; | ||
| 593 | break; | ||
| 594 | } | ||
| 595 | |||
| 590 | 596 | int_type __c = __buf->sbumpc(); // sschwarz | |
| 591 | 597 | ||
| 592 | 598 | if (__that->_S_eof(__c)) { | |
| 593 | 599 | if (__n < _Num || __is_getline) | |
| 594 | 600 | __status |= ios_base::eofbit; | |
| 595 | 601 | break; | |
| 596 | } | ||
| 597 | else if (__is_delim(_Traits::to_char_type(__c))) { | ||
| 602 | } else if (__is_delim(_Traits::to_char_type(__c))) { | ||
| 598 | 603 | if (__extract_delim) { // Extract and discard current character. | |
| 599 | 604 | ++__n; | |
| 600 | 605 | } else if ( !__pushback(__buf, _Traits::to_char_type(__c)) ) { // leave delimiter | |
| … | … | ||
| 607 | 607 | } | |
| 608 | 608 | break; | |
| 609 | 609 | } | |
| 610 | else { // regular character | ||
| 611 | *__s++ = _Traits::to_char_type(__c); | ||
| 612 | ++__n; | ||
| 613 | } | ||
| 614 | |||
| 615 | if (__n == _Num) { | ||
| 616 | if (__is_getline) // didn't find delimiter as one of the _Num chars | ||
| 617 | __status |= ios_base::failbit; | ||
| 618 | break; | ||
| 619 | } | ||
| 610 | // regular character | ||
| 611 | *__s++ = _Traits::to_char_type(__c); | ||
| 612 | ++__n; | ||
| 620 | 613 | } | |
| 621 | 614 | } | |
| 622 | 615 | _STLP_CATCH_ALL { |
test/unit/fstream_test.cpp
(54 / 0)
|   | |||
| 49 | 49 | CPPUNIT_TEST(streambuf_output); | |
| 50 | 50 | CPPUNIT_STOP_IGNORE; | |
| 51 | 51 | CPPUNIT_TEST(win32_file_format); | |
| 52 | CPPUNIT_TEST(null_buf); | ||
| 52 | 53 | # if defined (CHECK_BIG_FILE) | |
| 53 | 54 | CPPUNIT_TEST(big_file); | |
| 54 | 55 | # endif | |
| … | … | ||
| 70 | 70 | void rdbuf(); | |
| 71 | 71 | void streambuf_output(); | |
| 72 | 72 | void win32_file_format(); | |
| 73 | void null_buf(); | ||
| 73 | 74 | void custom_facet(); | |
| 74 | 75 | # if !defined (STLPORT) || !defined (_STLP_WIN32) | |
| 75 | 76 | void offset(); | |
| … | … | ||
| 384 | 384 | CPPUNIT_ASSERT( nb_read_lines == nb_lines ); | |
| 385 | 385 | CPPUNIT_ASSERT( !last_line.empty() && (last_line[0] == '\r') ); | |
| 386 | 386 | } | |
| 387 | } | ||
| 388 | |||
| 389 | void FstreamTest::null_buf() | ||
| 390 | { | ||
| 391 | /* ********************************************************************************** | ||
| 392 | |||
| 393 | testcase for bug #1830513: | ||
| 394 | in _istream.c | ||
| 395 | |||
| 396 | template < class _CharT, class _Traits, class _Is_Delim> | ||
| 397 | streamsize _STLP_CALL __read_unbuffered(basic_istream<_CharT, _Traits>* __that, | ||
| 398 | basic_streambuf<_CharT, _Traits>* __buf, | ||
| 399 | streamsize _Num, _CharT* __s, | ||
| 400 | _Is_Delim __is_delim, | ||
| 401 | bool __extract_delim, bool __append_null, | ||
| 402 | bool __is_getline) | ||
| 403 | |||
| 404 | can't accept _Num == 0; this is legal case, and may happen from | ||
| 405 | |||
| 406 | template <class _CharT, class _Traits> | ||
| 407 | basic_istream<_CharT, _Traits>& | ||
| 408 | basic_istream<_CharT, _Traits>::getline(_CharT* __s, streamsize __n, _CharT __delim) | ||
| 409 | |||
| 410 | *********************************************************************************** */ | ||
| 411 | |||
| 412 | fstream f( "test.txt", ios_base::in | ios_base::out | ios_base::trunc ); | ||
| 413 | // string line; | ||
| 414 | |||
| 415 | for ( int i = 0; i < 0x200; ++i ) { | ||
| 416 | f.put( ' ' ); | ||
| 417 | } | ||
| 418 | |||
| 419 | // const streambuf *b = f.rdbuf(); | ||
| 420 | |||
| 421 | // string s; | ||
| 422 | char buf[1024]; | ||
| 423 | buf[0] = 'a'; | ||
| 424 | buf[1] = 'b'; | ||
| 425 | buf[2] = 'c'; | ||
| 426 | |||
| 427 | // getline( f, s ); | ||
| 428 | // cerr << f.good() << endl; | ||
| 429 | f.seekg( 0, ios_base::beg ); | ||
| 430 | // f.seekg( 0, ios_base::end ); | ||
| 431 | // buf[0] = f.get(); | ||
| 432 | |||
| 433 | // cerr << (void *)(b->_M_gptr()) << " " << (void *)(b->_M_egptr()) << endl; | ||
| 434 | // cerr << f.good() << endl; | ||
| 435 | // getline( f, s ); | ||
| 436 | f.getline( buf, 1 ); // <-- key line | ||
| 437 | CPPUNIT_CHECK( buf[0] == 0 ); | ||
| 438 | CPPUNIT_CHECK( f.fail() ); // due to delimiter not found while buffer was exhausted | ||
| 387 | 439 | } | |
| 388 | 440 | ||
| 389 | 441 | #if defined (DO_CUSTOM_FACET_TEST) |

