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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@273820 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2016-06-26 19:48:29 +00:00
parent 8c4dc32424
commit 256f000cdc
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;
}