Commit b9701bffe647e16fde3d5ede3066a4a6e9997135

  • avatar
  • complement <complement @01b27279-081b-0410…d9d9e0fb0389.>
  • Tue Nov 13 12:02:36 CET 2007
  • Tree SHA1: 5513ca9
  • Parent SHA1: e0b3e23 (Add missing const_cast in lock free allocator implementation when _STLP_LEAKS_PEDANTIC is defined.)
  • raw diff | raw patch
testcase and fix for bug #1830513: __read_unbuffered wrongly process valid streamsize 0

git-svn-id: https://stlport.svn.sourceforge.net/svnroot/stlport/branches/STLPORT_5_1/STLport@3242 01b27279-081b-0410-8cf9-d9d9e0fb0389
  
12007-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
1102007-10-21 Francois Dumont <dums@users.sourceforge.net>
211
312 * src/allocators.cpp: Add missing const_cast in lock free
  
578578 streamsize _Num, _CharT* __s,
579579 _Is_Delim __is_delim,
580580 bool __extract_delim, bool __append_null,
581 bool __is_getline) {
581 bool __is_getline)
582{
582583 streamsize __n = 0;
583584 ios_base::iostate __status = 0;
584585
587587 // The operations that can potentially throw are sbumpc, snextc, and sgetc.
588588 _STLP_TRY {
589589 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
590596 int_type __c = __buf->sbumpc(); // sschwarz
591597
592598 if (__that->_S_eof(__c)) {
593599 if (__n < _Num || __is_getline)
594600 __status |= ios_base::eofbit;
595601 break;
596 }
597 else if (__is_delim(_Traits::to_char_type(__c))) {
602 } else if (__is_delim(_Traits::to_char_type(__c))) {
598603 if (__extract_delim) { // Extract and discard current character.
599604 ++__n;
600605 } else if ( !__pushback(__buf, _Traits::to_char_type(__c)) ) { // leave delimiter
607607 }
608608 break;
609609 }
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;
620613 }
621614 }
622615 _STLP_CATCH_ALL {
  
4949 CPPUNIT_TEST(streambuf_output);
5050 CPPUNIT_STOP_IGNORE;
5151 CPPUNIT_TEST(win32_file_format);
52 CPPUNIT_TEST(null_buf);
5253# if defined (CHECK_BIG_FILE)
5354 CPPUNIT_TEST(big_file);
5455# endif
7070 void rdbuf();
7171 void streambuf_output();
7272 void win32_file_format();
73 void null_buf();
7374 void custom_facet();
7475# if !defined (STLPORT) || !defined (_STLP_WIN32)
7576 void offset();
384384 CPPUNIT_ASSERT( nb_read_lines == nb_lines );
385385 CPPUNIT_ASSERT( !last_line.empty() && (last_line[0] == '\r') );
386386 }
387}
388
389void 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
387439}
388440
389441#if defined (DO_CUSTOM_FACET_TEST)