MCPcopy Create free account
hub / github.com/DFHack/dfhack / check_malloc_perturb

Function check_malloc_perturb

plugins/devel/check-structures-sanity/main.cpp:37–51  ·  view source on GitHub ↗

returns 0 if MALLOC_PERTURB_ is unset, or if set to 0, because 0 is not useful

Source from the content-addressed store, hash-verified

35
36// returns 0 if MALLOC_PERTURB_ is unset, or if set to 0, because 0 is not useful
37uint8_t check_malloc_perturb()
38{
39 const size_t TEST_DATA_LEN = 5000; // >1 4kb page
40 std::unique_ptr<uint8_t[]> test_data{new uint8_t[TEST_DATA_LEN]};
41
42 uint8_t expected_perturb = test_data[0];
43 if (getenv("MALLOC_PERTURB_"))
44 expected_perturb = 0xff ^ static_cast<uint8_t>(atoi(getenv("MALLOC_PERTURB_")));
45
46 for (size_t i = 0; i < TEST_DATA_LEN; i++)
47 if (expected_perturb != test_data[i])
48 return 0;
49
50 return expected_perturb;
51}
52
53static command_result command(color_ostream & out, std::vector<std::string> & parameters)
54{

Callers 1

commandFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected