Uploaded image for project: 'C++ Standard Library'
  1. C++ Standard Library
  2. STDCXX-1026

sgetn() fails to extract characters from an unbuffered stream

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.2.1
    • 4.2.2
    • 27. Input/Output
    • None
    • Incorrect Behavior

    Description

      This bug was uncovered in this discussion :

      $ cat t.cpp && make t && ./t
      #include <cassert>
      #include <istream>
      #include <streambuf>
      
      int main ()
      {
          static int x = '0';
      
          struct: std::streambuf {
              // unbuffered, always successfully reads one character
              int_type underflow () { return x++; }
          } sb;
      
          // "endless" stream that never reaches EOF
          std::istream endless (&sb);
      
          char s [4] = "";
      
          endless.read (s, sizeof s);
       
          // expect to extract as many characters as requested
          assert (endless.good ());
          assert (sizeof s == endless.gcount ());
          assert ('0' == s [0] && '1' == s [1] && '2' == s [2] && '3' == s [3]);
          
      }
      gcc -c -I/home/sebor/stdcxx-4.2.1/include/ansi \
             -I/home/sebor/stdcxx-4.2.1/include \
             -I/build/sebor/stdcxx-4.2.1-gcc-4.3.0-8D/include \
             -I/home/sebor/stdcxx-4.2.1/examples/include \
             -pedantic -nostdinc++ -O2   -W -Wall \
             -Wcast-qual -Winline -Wshadow -Wwrite-strings -Wno-long-long -Wcast-align   t.cpp
      t.cpp: In function 'int main()':
      t.cpp:9: warning: inlining failed in call to 'virtual main()::<anonymous struct>::~._26()': call is unlikely and code size would grow
      t.cpp:24: warning: called from here
      t.cpp:9: warning: inlining failed in call to 'virtual main()::<anonymous struct>::~._26()': call is unlikely and code size would grow
      t.cpp:24: warning: called from here
      gcc t.o -o t  -L/build/sebor/stdcxx-4.2.1-gcc-4.3.0-8D/lib  -Wl,-R/build/sebor/stdcxx-4.2.1-gcc-4.3.0-8D/lib -lstd8D -lsupc++ -lm 
      t: t.cpp:22: int main(): Assertion `endless.good ()' failed.
      Aborted
      

      Attachments

        Activity

          People

            sebor Martin Sebor
            sebor Martin Sebor
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 2h Original Estimate - 2h
                2h
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 4h
                4h