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

std::string::append (InputIterator, InputIterator) appending self incorrect

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 4.1.2, 4.1.3, 4.1.4, 4.2.0
    • 4.2.1
    • 21. Strings
    • None
    • all

    • Incorrect Behavior

    Description

      The 21.string.append.cpp test has been failing a number of assertions for self-referential test cases that exercise the ability to append a substring of a string into itself using the append(InputIterator, InputIterator) member template specialization for InputIterator being an actual Input Iterator. The program below reproduces the problem in a small isolated test case.

      $ cat t.cpp && gmake t && ./t
      #include <cassert>
      #include <cstdlib>
      #include <cstring>
      #include <iterator>
      #include <new>
      #include <string>
      
      void* operator new (std::size_t n) throw (std::bad_alloc)
      {
          void* const ptr = std::malloc (n + sizeof n);
          std::memset (ptr, -1, n);
          *(std::size_t*)ptr = n;
          return (std::size_t*)ptr + 1;
      }
      
      void operator delete (void *ptr) throw ()
      {
          std::memset (ptr, -1, *((std::size_t*)ptr - 1));
          std::free ((std::size_t*)ptr - 1);
          
      }
      
      struct InputIterator: std::iterator<std::input_iterator_tag, char>
      {
          const char *p_;
          InputIterator (const char *p): p_ (p) { }
      
          char operator* () const { return *p_; }
          InputIterator& operator++ () { return ++p_, *this; }
          InputIterator operator++ (int) {
              return ++p_, InputIterator (p_ - 1);
          }
      
          bool operator== (const InputIterator &rhs) const { return p_ == rhs.p_; }
      };
      
      
      int main ()
      {
          const char s[] = "abc";
      
          {
              std::string str (s);
      
              const char* p0 = s + 1;
              const char* p1 = p0 + 1;
      
              const InputIterator first (p0);
              const InputIterator last (p1);
      
              str.append (first, last);
      
              assert ("abcb" == str);
          }
      
          {
              std::string str (s);
      
              const char* p0 = str.data () + 1;
              const char* p1 = p0 + 1;
      
              const InputIterator first (p0);
              const InputIterator last (p1);
      
              str.append (first, last);
      
              assert ("abcb" == str);
          }
      }
      
      aCC -c -I/amd/devco/sebor/stdcxx/include/ansi -I/usr/include  -D_RWSTDDEBUG   -mt -D_RWSTD_USE_CONFIG -I/amd/devco/sebor/stdcxx/include -I/build/sebor/stdcxx-aCC-3.73-15D/include -I/amd/devco/sebor/stdcxx/tests/include  -Aa +nostl  -g +d  +DD64 +w +W392 +W655 +W684 +W818 +W819 +W849   t.cpp
      aCC t.o -o t -L/build/sebor/stdcxx-aCC-3.73-15D/rwtest -lrwtest15D -Aa +nostl -Wl,+s -Wl,+vnocompatwarnings   -mt +DD64 -L/build/sebor/stdcxx-aCC-3.73-15D/lib  -Wl,+b/build/sebor/stdcxx-aCC-3.73-15D/lib:/build/sebor/stdcxx-aCC-3.73-15D/rwtest -lstd15D  -lm 
      Assertion failed: "abcb" == str, file t.cpp, line 67
      ABORT instruction (core dumped)
      

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 8h
                  8h
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 8h
                  8h