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

attempting to create a std::string of size 65535 or greater fails with Perennial CPPVS V8.1

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 4.2.1, 4.2.x, 4.3.x, 5.0.0
    • Fix Version/s: 4.2.x, 4.3.x, 5.0.0
    • Component/s: 21. Strings
    • Environment:

      Solaris 10 and 11, RedHat Linux, OpenSuSE Linux
      SUN C++ Compilers 12.1, 12.2, 12.3
      Defect is independent of compiler and platform

    • Patch Info:
      Patch Available
    • Regression:
      Regression, Unit Test Broken
    • Severity:
      Incorrect Behavior

      Description

      in member function:

      size_type basic_string<_CharT, _Traits, _Allocator>::max_size();

      the maximum size of a basic_string is restricted to less than 65535 bytes.
      The Standard is ambiguous as to what the max_size() of a std::string should
      actually be (see LWG Core Issue 197). However, less than 65535 bytes for
      the max_size of a std::string is rather small. GNU libstdc++ and stlport4
      set std::string::max_size to (SIZE_MAX / 4) (i.e. 1GB). Solaris sets it
      to SIZE_MAX.

      Perennial CPPVS explicitly tests for the creation of a std::string of size
      greater than 65535. In the current stdcxx implementation, this test fails.

      The max_size of a std::string should be significantly greater than 65535 bytes.

      Test to reproduce the defect:

      test.cc
      #include <iostream>
      #include <string>
      
      const size_t maxlen = 65536U;
      char array[maxlen];
      
      struct test_traits : public std::char_traits<char>
      { };
      
      template<class T>
      struct test_alloc : public std::allocator<T>
      {
          typedef typename std::allocator<T>::size_type size_type;
      
          template<class Y>
          struct rebind
          {
              typedef test_alloc<Y> other;
          };
      
          test_alloc() throw() { }
          test_alloc(const test_alloc& rhs) throw() { }
      
          template<class Y>
          test_alloc(const test_alloc<Y>& y) throw() { }
      
          ~test_alloc() throw() { }
      
          size_type max_size() const throw() { return maxlen; }
      };
      
      int main()
      {
          typedef
          std::basic_string<char, test_traits, test_alloc<char> > test_string;
      
          int ret = 0;
          size_t i, j;
      
          for (i = 0; i < maxlen; i++)
              array[i] = '*';
      
          array[maxlen - 1] = '\0';
      
          for (i = 0; i < maxlen - 1; i+= 8)
          {
              array[i] = '\0';
              test_string s(array);
      
              j = s.size();
              array[i] = '-';
      
              if (i != j)
              {
                  std::cerr << "i = " << i << " j = " << j << " expected i == j"
                            << std::endl;
                  ret = 1;
                  break;
              }
          }
      
          return ret;
      }
      

      1. Output from GCC 4.5.0:

      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/6889771][02/06/2012 10:16:34][2162]>> ./test-gcc
      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/6889771][02/06/2012 10:16:48][2163]>> echo $status
      0
      

      2. Output from Sun C++ 12.2 with stlport:

      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/6889771][02/06/2012 10:16:50][2164]>> ./test-ss122-stlport 
      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/6889771][02/06/2012 10:16:58][2165]>> echo $status
      0
      

      3. Output from Sun C++ 12.2 with our patched stdcxx:

      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/6889771][02/06/2012 10:17:00][2166]>> ./test-ss122-stdcxx 
      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/6889771][02/06/2012 10:17:06][2167]>> echo $status
      0
      

      4. Output from Pathscale 4.0.12.1 (which did not patch stdcxx):

      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/6889771][02/06/2012 10:17:08][2168]>> ./test-pathscale 
      Terminating due to uncaught exception 0x614240 of type std::length_error
      Abort (core dumped)
      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/6889771][02/06/2012 10:17:13][2169]>> echo $status
      134
      

      Patch for 4.2.1 to follow shortly.

        Attachments

        1. stdcxx-1057.patch
          0.8 kB
          Stefan Teleman
        2. test.cc
          1 kB
          Stefan Teleman

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              steleman Stefan Teleman
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: