From b9291d95f02c391dcfef1faf17165e1ff88e4700 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 28 Sep 2019 17:39:30 +1000 Subject: [PATCH] HAL_SITL: pre-fill stack on each loop with NaN this allows us to catch use of uninitialised stack variables in SITL without having valgrind running --- libraries/AP_HAL_SITL/HAL_SITL_Class.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libraries/AP_HAL_SITL/HAL_SITL_Class.cpp b/libraries/AP_HAL_SITL/HAL_SITL_Class.cpp index 9388febcf9..fc2c4a7511 100644 --- a/libraries/AP_HAL_SITL/HAL_SITL_Class.cpp +++ b/libraries/AP_HAL_SITL/HAL_SITL_Class.cpp @@ -136,6 +136,16 @@ void HAL_SITL::setup_signal_handlers() const sigaction(SIGTERM, &sa, NULL); } +/* + fill 8k of stack with NaN. This allows us to find uses of + uninitialised memory without valgrind + */ +static void fill_stack_nan(void) +{ + float stk[2048]; + fill_nanf(stk, ARRAY_SIZE(stk)); +} + void HAL_SITL::run(int argc, char * const argv[], Callbacks* callbacks) const { assert(callbacks); @@ -168,6 +178,8 @@ void HAL_SITL::run(int argc, char * const argv[], Callbacks* callbacks) const new_argv[new_argv_offset++] = argv[i]; } + fill_stack_nan(); + callbacks->setup(); scheduler->system_initialized(); @@ -197,6 +209,7 @@ void HAL_SITL::run(int argc, char * const argv[], Callbacks* callbacks) const ::fprintf(stderr, "Exitting\n"); exit(0); } + fill_stack_nan(); callbacks->loop(); HALSITL::Scheduler::_run_io_procs();