diff --git a/plugins/devel/check-structures-sanity/check-structures-sanity.h b/plugins/devel/check-structures-sanity/check-structures-sanity.h index b606e9d86..ec27cd25a 100644 --- a/plugins/devel/check-structures-sanity/check-structures-sanity.h +++ b/plugins/devel/check-structures-sanity/check-structures-sanity.h @@ -82,6 +82,7 @@ public: bool failfast; bool noprogress; bool maybepointer; + uint8_t perturb_byte; Checker(color_ostream & out); bool queue_item(const QueueItem & item, CheckedStructure cs); diff --git a/plugins/devel/check-structures-sanity/dispatch.cpp b/plugins/devel/check-structures-sanity/dispatch.cpp index c0d4764f9..9d9198744 100644 --- a/plugins/devel/check-structures-sanity/dispatch.cpp +++ b/plugins/devel/check-structures-sanity/dispatch.cpp @@ -296,7 +296,7 @@ void Checker::dispatch_primitive(const QueueItem & item, const CheckedStructure else if (cs.identity == df::identity_traits::get()) { auto val = *reinterpret_cast(item.ptr); - if (val > 1 && val != 0xd2) + if (val > 1 && perturb_byte && val != perturb_byte && val != (perturb_byte ^ 0xff)) { FAIL("invalid value for bool: " << int(val)); } diff --git a/plugins/devel/check-structures-sanity/main.cpp b/plugins/devel/check-structures-sanity/main.cpp index 909c25dac..cefe14138 100644 --- a/plugins/devel/check-structures-sanity/main.cpp +++ b/plugins/devel/check-structures-sanity/main.cpp @@ -33,28 +33,33 @@ DFhackCExport command_result plugin_init(color_ostream &, std::vectordata[0] == 0xd2d2d2d2); - delete test; - return ret; + const size_t TEST_DATA_LEN = 5000; // >1 4kb page + std::unique_ptr test_data{new uint8_t[TEST_DATA_LEN]}; + + uint8_t expected_perturb = test_data[0]; + if (getenv("MALLOC_PERTURB_")) + expected_perturb = 0xff ^ static_cast(atoi(getenv("MALLOC_PERTURB_"))); + + for (size_t i = 0; i < TEST_DATA_LEN; i++) + if (expected_perturb != test_data[i]) + return 0; + + return expected_perturb; } static command_result command(color_ostream & out, std::vector & parameters) { - if (!check_malloc_perturb()) - { - out.printerr("check-structures-sanity: MALLOC_PERTURB_ not set, cannot continue\n"); - return CR_FAILURE; - } + uint8_t perturb_byte = check_malloc_perturb(); + if (!perturb_byte) + out.printerr("check-structures-sanity: MALLOC_PERTURB_ not set. Some checks may be bypassed or fail.\n"); CoreSuspender suspend; Checker checker(out); + checker.perturb_byte = perturb_byte; // check parameters with values first #define VAL_PARAM(name, expr_using_value) \