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