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

std::istream::getline(char*, size_type) doesn't store NUL on failure

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.1.2
    • Fix Version/s: 4.1.3
    • Component/s: 27. Input/Output
    • Labels:
      None
    • Environment:

      all

      Description

      The program below aborts at runtime. According to lib.istream.unformatted, p20:
      "[getline...] stores a null character (using charT()) into the next successive location of the array."

      $ cat t.cpp && nice make t -r && ./t
      #include <cassert>
      #include <sstream>

      int main ()
      {
      std::istringstream strm;

      strm.setstate (strm.failbit);

      char s [3] =

      { 'x', 'y', 'z' }

      ;
      strm.getline (s, 2);

      assert ('\0' == s [0]);
      assert ('y' == s [1]);
      assert ('z' == s [2]);
      }

      gcc -c -I/build/sebor/dev/stdlib/include/ansi -D_RWSTDDEBUG -pthreads -D_RWSTD_USE_CONFIG -I/build/sebor/gcc-3.4.3-15s/include -I/build/sebor/dev/stdlib/include -I/build/sebor/dev/stdlib/../rwtest -I/build/sebor/dev/stdlib/../rwtest/include -I/build/sebor/dev/stdlib/tests/include -pedantic -nostdinc++ -g -Wall -W -Wcast-qual -Winline -Wshadow -Wwrite-strings -Wno-long-long t.cpp
      gcc t.o -o t -L/build/sebor/gcc-3.4.3-15s/rwtest -lrwtest15s -pthreads -L/build/sebor/gcc-3.4.3-15s/lib -lstd15s -lsupc++ -lm
      Assertion failed: '\0' == s [0], file t.cpp, line 13
      Abort (core dumped)

        Attachments

          Activity

            People

            • Assignee:
              sebor Martin Sebor
              Reporter:
              sebor Martin Sebor
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h
                1h