Line data Source code
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 380 : void* memcpy_int(void* a, const void* b, size_t c) 14 : { 15 380 : 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 380 : bool sanity_test_memcpy() 27 : { 28 : unsigned int memcpy_test[T]; 29 380 : unsigned int memcpy_verify[T] = {}; 30 389880 : for (unsigned int i = 0; i != T; ++i) 31 389500 : memcpy_test[i] = i; 32 : 33 380 : memcpy_int(memcpy_verify, memcpy_test, sizeof(memcpy_test)); 34 : 35 389880 : for (unsigned int i = 0; i != T; ++i) { 36 389500 : if (memcpy_verify[i] != i) 37 : return false; 38 : } 39 : return true; 40 : } 41 : 42 : } // anon namespace 43 : 44 380 : bool glibc_sanity_test() 45 : { 46 380 : return sanity_test_memcpy<1025>(); 47 : }