From 40dff737c569223806c575d0652e271812fdbce2 Mon Sep 17 00:00:00 2001 From: Peter Duerr Date: Mon, 7 Aug 2017 15:39:56 +0200 Subject: [PATCH] Fix uninitialized values identified by cppcheck * Replace `malloc` by `calloc` for c-string initialization * Add initializer braces for structs --- src/modules/ekf2_replay/ekf2_replay_main.cpp | 2 +- src/modules/uORB/uORB_tests/uORBTest_UnitTest.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/ekf2_replay/ekf2_replay_main.cpp b/src/modules/ekf2_replay/ekf2_replay_main.cpp index 86db74f5cc..0b10bdddb0 100644 --- a/src/modules/ekf2_replay/ekf2_replay_main.cpp +++ b/src/modules/ekf2_replay/ekf2_replay_main.cpp @@ -839,7 +839,7 @@ void Ekf2Replay::task_main() // create path which tells user location of replay file char tmp2[] = "./build_posix_sitl_replay/src/firmware/posix"; - char *replay_file_location = (char *) malloc(1 + strlen(tmp) + strlen(tmp2) + strlen(replay_log_name)); + char *replay_file_location = (char *) calloc(1 + strlen(tmp) + strlen(tmp2) + strlen(replay_log_name), 1); strcat(replay_file_location, tmp2); strcat(replay_file_location, replay_log_name); strcat(replay_file_location, tmp); diff --git a/src/modules/uORB/uORB_tests/uORBTest_UnitTest.cpp b/src/modules/uORB/uORB_tests/uORBTest_UnitTest.cpp index 26666a07f3..f5d443ea40 100644 --- a/src/modules/uORB/uORB_tests/uORBTest_UnitTest.cpp +++ b/src/modules/uORB/uORB_tests/uORBTest_UnitTest.cpp @@ -317,7 +317,7 @@ int uORBTest::UnitTest::test_multi() /* this routine tests the multi-topic support */ test_note("try multi-topic support"); - struct orb_test t, u; + struct orb_test t {}, u {}; t.val = 0; int instance0; _pfd[0] = orb_advertise_multi(ORB_ID(orb_multitest), &t, &instance0, ORB_PRIO_MAX); @@ -536,7 +536,7 @@ int uORBTest::UnitTest::test_multi_reversed() return test_fail("sub. id2: ret: %d", sfd2); } - struct orb_test t, u; + struct orb_test t {}, u {}; t.val = 0;