Add array bounds assertions to satisfy MSVC's /analyze flag. Patch from STL@microsoft.com

llvm-svn: 273820
This commit is contained in:
Eric Fiselier 2016-06-26 19:48:29 +00:00
parent 3740071be0
commit 2e0e3df9da
3 changed files with 11 additions and 0 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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]);