Author: vitek
Date: Wed Jun  4 14:48:36 2008
New Revision: 663377

URL: http://svn.apache.org/viewvc?rev=663377&view=rev
Log:
2008-06-04  Travis Vitek  <[EMAIL PROTECTED]>

        STDCXX-955
        * include/valarray: Correctly calculate indices when the
        length array contains a zero.
        * src/valarray.cpp: Ditto.
        * tests/numerics/26.class.gslice.cpp (make_array): Update to
        handle empty strings or other poorly formatted input.
        (get_array_size, next_index): Correctly calculate indices
        when the slice length array contains a zero.
        (test_gslice): Remove unnecessary line feed from assertion.
        (run_test): Update degenerate testcase to match comment.
        * tests/regress/26.valarray.sub.stdcxx-995.cpp: Add new
        regression test.

Added:
    stdcxx/branches/4.2.x/tests/regress/26.valarray.sub.stdcxx-955.cpp   (with 
props)
Modified:
    stdcxx/branches/4.2.x/include/valarray
    stdcxx/branches/4.2.x/src/valarray.cpp
    stdcxx/branches/4.2.x/tests/numerics/26.class.gslice.cpp

Modified: stdcxx/branches/4.2.x/include/valarray
URL: 
http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/include/valarray?rev=663377&r1=663376&r2=663377&view=diff
==============================================================================
--- stdcxx/branches/4.2.x/include/valarray (original)
+++ stdcxx/branches/4.2.x/include/valarray Wed Jun  4 14:48:36 2008
@@ -2039,10 +2039,12 @@
     if (_C_length.size () == 0)
         return 0;
 
-    _RWSTD_SIZE_T __inx = 1;
+    _RWSTD_SIZE_T __inx = _C_length [0] != 0;
 
-    for(_RWSTD_SIZE_T __i = 0; __i < _C_length.size (); ++__i)
-        __inx *= _C_length [__i];
+    for(_RWSTD_SIZE_T __i = 0; __i < _C_length.size (); ++__i) {
+        if (_C_length [__i])
+            __inx *= _C_length [__i];
+    }
 
     return __inx;
 }

Modified: stdcxx/branches/4.2.x/src/valarray.cpp
URL: 
http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/src/valarray.cpp?rev=663377&r1=663376&r2=663377&view=diff
==============================================================================
--- stdcxx/branches/4.2.x/src/valarray.cpp (original)
+++ stdcxx/branches/4.2.x/src/valarray.cpp Wed Jun  4 14:48:36 2008
@@ -41,8 +41,12 @@
 {
     _RWSTD_SIZE_T __n = _C_length.size ();
 
-    while (__n && _C_r_length [__n - 1] == _C_length [__n - 1] - 1)
-        --__n;
+    for (/**/; __n; --__n)
+    {
+        if (   _C_length [__n - 1]
+            && _C_r_length [__n - 1] != _C_length [__n - 1] - 1)
+            break;
+    }
 
     if (0 == __n) {
         _C_reset    = true;

Modified: stdcxx/branches/4.2.x/tests/numerics/26.class.gslice.cpp
URL: 
http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/tests/numerics/26.class.gslice.cpp?rev=663377&r1=663376&r2=663377&view=diff
==============================================================================
--- stdcxx/branches/4.2.x/tests/numerics/26.class.gslice.cpp (original)
+++ stdcxx/branches/4.2.x/tests/numerics/26.class.gslice.cpp Wed Jun  4 
14:48:36 2008
@@ -35,25 +35,28 @@
 static std::valarray<std::size_t>
 make_array (const char *s)
 {
-    if (0 == s)
-        return std::valarray<std::size_t>();
-
     std::size_t buf [256];
 
-    for (std::size_t i = 0; ; ++i) {
+    std::size_t i = 0;
+    while (s && *s) {
 
         char *end;
         unsigned long val = std::strtoul (s, &end, 10);
 
         RW_ASSERT ('\0' == *end || ',' == *end);
 
-        buf [i] = std::size_t (val);
+        if (s == end)
+            break;
+
+        buf [i++] = std::size_t (val);
 
         if ('\0' == *end)
-            return std::valarray<std::size_t>(buf, i + 1);
+            break;
 
         s = end + 1;
     }
+
+    return std::valarray<std::size_t>(buf, i);
 }
 
 /**************************************************************************/
@@ -67,7 +70,8 @@
     std::size_t asize = sizes.size () ? 1 : 0;
 
     for (std::size_t i = 0; i != sizes.size (); ++i) {
-        asize *= sizes [i];
+        if (sizes [i])
+            asize *= sizes [i];
     }
 
     return asize;
@@ -92,8 +96,11 @@
         return start;
     }
 
-    while (inx && factors [inx - 1] == asizes [inx - 1] - 1)
-        --inx;
+    for (/**/; inx; --inx) {
+        if (   asizes [inx - 1]
+            && factors [inx - 1] != asizes [inx - 1] - 1)
+            break;
+    }
 
     if (0 == inx) {
         factors = 0;
@@ -156,12 +163,12 @@
         if (maxinx < indices [i])
             maxinx = indices [i];
 
-    std::valarray<std::size_t> va (maxinx + 1);
+    std::valarray<std::size_t> va (indices.size () ? maxinx + 1 : 0);
     for (std::size_t i = 0; i != va.size (); ++i)
         va [i] = i;
 
     for (int i = 0; i != 3; ++i) {
-        // repeat each test three to verify that operator[](gslice)
+        // repeat each test thrice to verify that operator[](gslice)
         // doesn't change the observable state of its argument and
         // that the same result is obtained for a copy of gslice
 
@@ -171,7 +178,7 @@
         bool equal = array_slice.size () == indices.size ();
 
         rw_assert (equal, 0, __LINE__,
-                   "size() == %zu, got %zu\n",
+                   "size() == %zu, got %zu",
                    indices.size (), array_slice.size ());
 
         if (equal) {
@@ -180,7 +187,7 @@
                 equal = array_slice [j] == va [indices [j]];
 
                 rw_assert (equal, 0, __LINE__,
-                           "mismatch at %u, index %u: expected %u, got %u\n",
+                           "mismatch at %u, index %u: expected %u, got %u",
                            j, indices [j], va [indices [j]],
                            array_slice [j]);
             }
@@ -223,7 +230,7 @@
     test_gslice ("2,4,3", "19,4,1");
 
     // includes example of a degenerate gslice from p5
-    test_gslice ("2,4,3", "19,4,1");
+    test_gslice ("2,4,3", "1,1,1");
 
     return 0;
 }

Added: stdcxx/branches/4.2.x/tests/regress/26.valarray.sub.stdcxx-955.cpp
URL: 
http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/tests/regress/26.valarray.sub.stdcxx-955.cpp?rev=663377&view=auto
==============================================================================
--- stdcxx/branches/4.2.x/tests/regress/26.valarray.sub.stdcxx-955.cpp (added)
+++ stdcxx/branches/4.2.x/tests/regress/26.valarray.sub.stdcxx-955.cpp Wed Jun  
4 14:48:36 2008
@@ -0,0 +1,59 @@
+/************************************************************************
+ *
+ * 26.valarray.sub.stdcxx-955.cpp - regression test for STDCXX-955
+ *
+ *   http://issues.apache.org/jira/browse/STDCXX-955
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1994-2008 Rogue Wave Software, Inc.
+ * 
+ **************************************************************************/
+
+#include <cstdlib>
+#include <valarray>
+#include <cassert>
+
+
+int main ()
+{
+    const std::size_t p_leng [] = { 2, 0 };
+    const std::size_t p_strd [] = { 1, 3 };
+
+    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 ('!', 4);
+
+    va_lhs [gs_slice] = '?';
+
+    assert (va_lhs [0] == '!');
+    assert (va_lhs [1] == '?');
+    assert (va_lhs [2] == '?');
+    assert (va_lhs [3] == '!');
+
+    return 0;
+}

Propchange: stdcxx/branches/4.2.x/tests/regress/26.valarray.sub.stdcxx-955.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: stdcxx/branches/4.2.x/tests/regress/26.valarray.sub.stdcxx-955.cpp
------------------------------------------------------------------------------
    svn:keywords = Id


Reply via email to