[libcxx] r273820 - Add array bounds assertions to satisfy MSVC's /analyze flag. Patch from STL at microsoft.com

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 26 12:48:30 PDT 2016


Author: ericwf
Date: Sun Jun 26 14:48:29 2016
New Revision: 273820

URL: http://llvm.org/viewvc/llvm-project?rev=273820&view=rev
Log:
Add array bounds assertions to satisfy MSVC's /analyze flag. Patch from STL at microsoft.com

Modified:
    libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort.pass.cpp
    libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort_comp.pass.cpp
    libcxx/trunk/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp

Modified: libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort.pass.cpp?rev=273820&r1=273819&r2=273820&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort.pass.cpp Sun Jun 26 14:48:29 2016
@@ -22,13 +22,17 @@ void
 test_larger_sorts(unsigned N, unsigned M)
 {
     assert(N != 0);
+    assert(N >= M);
     int* array = new int[N];
     for (int i = 0; i < N; ++i)
         array[i] = i;
     std::random_shuffle(array, array+N);
     std::partial_sort(array, array+M, array+N);
     for (int i = 0; i < M; ++i)
+    {
+        assert(i < N); // quiet analysis warnings
         assert(array[i] == i);
+    }
     delete [] array;
 }
 

Modified: libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort_comp.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort_comp.pass.cpp?rev=273820&r1=273819&r2=273820&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort_comp.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort_comp.pass.cpp Sun Jun 26 14:48:29 2016
@@ -35,13 +35,17 @@ void
 test_larger_sorts(unsigned N, unsigned M)
 {
     assert(N != 0);
+    assert(N >= M);
     int* array = new int[N];
     for (int i = 0; i < N; ++i)
         array[i] = i;
     std::random_shuffle(array, array+N);
     std::partial_sort(array, array+M, array+N, std::greater<int>());
     for (int i = 0; i < M; ++i)
+    {
+        assert(i < N); // quiet analysis warnings
         assert(array[i] == N-i-1);
+    }
     delete [] array;
 }
 

Modified: libcxx/trunk/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp?rev=273820&r1=273819&r2=273820&view=diff
==============================================================================
--- libcxx/trunk/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp (original)
+++ libcxx/trunk/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp Sun Jun 26 14:48:29 2016
@@ -243,6 +243,7 @@ test4()
             a = 0;
             for (int j = 0; j < k; ++j)
                 a += areas[j];
+            assert(k < Np);
             m = (p[k+1] - p[k]) / (b[k+1] - b[k]);
             bk = b[k];
             c = (b[k+1]*p[k] - b[k]*p[k+1]) / (b[k+1] - b[k]);
@@ -281,6 +282,7 @@ test5()
     double S = 0;
     for (int i = 0; i < areas.size(); ++i)
     {
+        assert(i < Np);
         areas[i] = (p[i]+p[i+1])*(b[i+1]-b[i])/2;
         S += areas[i];
     }
@@ -296,6 +298,7 @@ test5()
             a = 0;
             for (int j = 0; j < k; ++j)
                 a += areas[j];
+            assert(k < Np);
             m = (p[k+1] - p[k]) / (b[k+1] - b[k]);
             bk = b[k];
             c = (b[k+1]*p[k] - b[k]*p[k+1]) / (b[k+1] - b[k]);




More information about the cfe-commits mailing list