Bitcoin Core  0.20.99
P2P Digital Currency
glibc_sanity.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2019 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #if defined(HAVE_CONFIG_H)
7 #endif
8 
9 #include <cstddef>
10 
11 extern "C" void* memcpy(void* a, const void* b, size_t c);
12 void* memcpy_int(void* a, const void* b, size_t c)
13 {
14  return memcpy(a, b, c);
15 }
16 
17 namespace
18 {
19 // trigger: Use the memcpy_int wrapper which calls our internal memcpy.
20 // A direct call to memcpy may be optimized away by the compiler.
21 // test: Fill an array with a sequence of integers. memcpy to a new empty array.
22 // Verify that the arrays are equal. Use an odd size to decrease the odds of
23 // the call being optimized away.
24 template <unsigned int T>
25 bool sanity_test_memcpy()
26 {
27  unsigned int memcpy_test[T];
28  unsigned int memcpy_verify[T] = {};
29  for (unsigned int i = 0; i != T; ++i)
30  memcpy_test[i] = i;
31 
32  memcpy_int(memcpy_verify, memcpy_test, sizeof(memcpy_test));
33 
34  for (unsigned int i = 0; i != T; ++i) {
35  if (memcpy_verify[i] != i)
36  return false;
37  }
38  return true;
39 }
40 } // namespace
41 
43 {
44  return sanity_test_memcpy<1025>();
45 }
void * memcpy_int(void *a, const void *b, size_t c)
bool glibc_sanity_test()
void * memcpy(void *a, const void *b, size_t c)