From 990952b6644e79da08c6925bddedff7c3b3ebe8a Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Sun, 19 Jun 2016 07:08:27 +0000 Subject: Fix various undefined behavior found by UBSan. * Fix non-null violation in strstream.cpp Overflow was calling memcpy with a null parameter and a size of 0. * Fix std/atomics/atomics.flag/ tests: a.test_and_set() was reading from an uninitialized atomic, but wasn't using the value. The tests now clear the flag before performing the first test_and_set. This allows UBSAN to test that clear doesn't read an invalid value. * Fix std/experimental/algorithms/alg.random.sample/sample.pass.cpp The tests were dereferencing a past-the-end pointer to an array so that they could do pointer arithmetic with it. Instead of dereference the iterator I changed the tests to use the special 'base()' test iterator method. * Add -fno-sanitize=float-divide-by-zero to suppress division by zero UBSAN diagnostics. The tests that cause float division by zero are explicitly aware that they are doing that. Since this is well defined for IEEE floats suppress the warnings for now. llvm-svn: 273107 --- .../algorithms/alg.random.sample/sample.pass.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'libcxx/test/std/experimental/algorithms/alg.random.sample/sample.pass.cpp') diff --git a/libcxx/test/std/experimental/algorithms/alg.random.sample/sample.pass.cpp b/libcxx/test/std/experimental/algorithms/alg.random.sample/sample.pass.cpp index 0f0784d6ee9..1a9f9b099b2 100644 --- a/libcxx/test/std/experimental/algorithms/alg.random.sample/sample.pass.cpp +++ b/libcxx/test/std/experimental/algorithms/alg.random.sample/sample.pass.cpp @@ -64,12 +64,12 @@ void test() { end = std::experimental::sample(PopulationIterator(ia), PopulationIterator(ia + is), SampleIterator(oa), os, g); - assert(&*end - oa == std::min(os, is)); + assert(end.base() - oa == std::min(os, is)); assert(std::equal(oa, oa + os, oa1)); end = std::experimental::sample(PopulationIterator(ia), PopulationIterator(ia + is), SampleIterator(oa), os, g); - assert(&*end - oa == std::min(os, is)); + assert(end.base() - oa == std::min(os, is)); assert(std::equal(oa, oa + os, oa2)); } @@ -85,7 +85,7 @@ void test_empty_population() { SampleIterator end = std::experimental::sample(PopulationIterator(ia), PopulationIterator(ia), SampleIterator(oa), os, g); - assert(&*end == oa); + assert(end.base() == oa); } template class PopulationIteratorType, class PopulationItem, @@ -100,7 +100,7 @@ void test_empty_sample() { SampleIterator end = std::experimental::sample(PopulationIterator(ia), PopulationIterator(ia + is), SampleIterator(oa), 0, g); - assert(&*end == oa); + assert(end.base() == oa); } template class PopulationIteratorType, class PopulationItem, @@ -119,8 +119,8 @@ void test_small_population() { end = std::experimental::sample(PopulationIterator(ia), PopulationIterator(ia + is), SampleIterator(oa), os, g); - assert(&*end - oa == std::min(os, is)); - assert(std::equal(oa, &*end, oa1)); + assert(end.base() - oa == std::min(os, is)); + assert(std::equal(oa, end.base(), oa1)); } int main() { -- cgit v1.2.3