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

infinite loop or out of bound access when slicing valarray

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 4.2.1
    • 4.2.2
    • 26. Numerics
    • None
    • Runtime Error

    Description

      The current valarray code does not handle creating a gslice that has a one or more empty steps. The following testcase will hang in an infinite loop.

      #include <cstdlib>
      #include <valarray>
      
      
      int main ()
      {
          const std::size_t p_leng [] = { 0 };
          const std::size_t p_strd [] = { 0 };
      
          const std::valarray<std::size_t> va_leng (p_leng,
              sizeof (p_leng) / sizeof (*p_leng));
      
          const std::valarray<std::size_t> va_strd (p_strd,
              sizeof (p_strd) / sizeof (*p_strd));
      
          const std::gslice gs_slice (1, va_leng, va_strd);
      
          std::valarray<char> va_lhs (10, '!');
      
          va_lhs [gs_slice] = '?';
      
         return 0;
      }
      

      Changing the declarations of p_len and p_strd to the following will result in an assertion or an out of bound access depending on build type.

          const std::size_t p_leng [] = { 2, 0 };
          const std::size_t p_strd [] = { 1, 3 };
      

      Attachments

        1. stdcxx-955.patch
          7 kB
          Travis Vitek

        Activity

          People

            vitek Travis Vitek
            vitek Travis Vitek
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

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