libstdc++: Fix buffer overflows in tests [PR 99382]

This seems to be a typo/thinko in the definition of the arrays used as
storage.

libstdc++-v3/ChangeLog:

	PR libstdc++/99382
	* testsuite/20_util/specialized_algorithms/uninitialized_default_n/sizes.cc:
	Make storage larger than required. Verify no write to the last
	element.
	* testsuite/20_util/specialized_algorithms/uninitialized_value_construct_n/sizes.cc:
	Likewise.
This commit is contained in:
Jonathan Wakely 2021-03-04 10:28:38 +00:00
parent f65e551f73
commit 905ce0ca30
2 changed files with 9 additions and 2 deletions

View File

@ -41,10 +41,12 @@ test02()
int operator>(void*) { return value != 0; }
};
int i[3];
int i[5] = { 1, 2, 3, 4, 5 };
Size n = {4};
auto j = std::__uninitialized_default_n(i, n);
VERIFY( j == (i + 4) );
// i[0:3] are default-initialized so have indeterminate values.
VERIFY( i[4] == 5 );
}
int

View File

@ -42,10 +42,15 @@ test02()
int operator>(void*) { return value != 0; }
};
int i[3];
int i[5] = { 1, 2, 3, 4, 5 };
Size n = {4};
auto j = std::__uninitialized_default_n(i, n);
VERIFY( j == (i + 4) );
VERIFY( i[0] == 0 );
VERIFY( i[1] == 0 );
VERIFY( i[2] == 0 );
VERIFY( i[3] == 0 );
VERIFY( i[4] == 5 );
}
int