diff options
author | Christopher Ferris <cferris@google.com> | 2016-02-12 17:24:27 -0800 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2016-02-12 18:09:55 -0800 |
commit | 71766c25778fe13717259cdccb62463684794408 (patch) | |
tree | 54c6c66a596ac1f86a79568cc6c70ab7d2fc06a3 /tests/string_test.cpp | |
parent | 9750a77b31f2fc6d548a02b3a9750c2794648fea (diff) |
Add a memcpy(a, a, n) test.
clang depends on memcpy where src and dst are the same to actually
work. Even though this is, technically, undefined behavior,
clang is not going to change. Add a test to verify this assumption
holds true for android devices.
Change-Id: Ib575af3c14e705bb62c18fad7d57e1cc0d242899
Diffstat (limited to 'tests/string_test.cpp')
-rw-r--r-- | tests/string_test.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/string_test.cpp b/tests/string_test.cpp index 96b414397..4b2cca247 100644 --- a/tests/string_test.cpp +++ b/tests/string_test.cpp @@ -24,6 +24,9 @@ #include <math.h> #include <stdint.h> +#include <algorithm> +#include <vector> + #include "buffer_tests.h" #if defined(NOFORTIFY) @@ -1432,3 +1435,23 @@ TEST(STRING_TEST, mempcpy) { char dst[6]; ASSERT_EQ(&dst[4], reinterpret_cast<char*>(mempcpy(dst, "hello", 4))); } + +// clang depends on the fact that a memcpy where src and dst is the same +// still operates correctly. This test verifies that this assumption +// holds true. +// See https://llvm.org/bugs/show_bug.cgi?id=11763 for more information. +static std::vector<uint8_t> g_memcpy_same_buffer; + +static void DoMemcpySameTest(uint8_t* buffer, size_t len) { + memcpy(buffer, g_memcpy_same_buffer.data(), len); + ASSERT_EQ(buffer, memcpy(buffer, buffer, len)); + ASSERT_TRUE(memcmp(buffer, g_memcpy_same_buffer.data(), len) == 0); +} + +TEST(STRING_TEST, memcpy_src_dst_same) { + g_memcpy_same_buffer.resize(MEDIUM); + for (size_t i = 0; i < MEDIUM; i++) { + g_memcpy_same_buffer[i] = i; + } + RunSingleBufferAlignTest(MEDIUM, DoMemcpySameTest); +} |