From f2092dd6905ecefef877355e6f086aac12f9298a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Mon, 7 May 2018 13:24:02 +0200 Subject: [PATCH] mixer_test: use snprintf instead of strncpy to fix compiler warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit compiler warning: ../../src/systemcmds/tests/test_mixer.cpp: In member function ‘bool MixerTest::loadAllTest()’: ../../src/systemcmds/tests/test_mixer.cpp:202:18: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying 1 byte from a string of the same length [-Werror=stringop-truncation] (void)strncpy(&buf[strlen(MIXER_ONBOARD_PATH)], "/", 1); --- src/systemcmds/tests/test_mixer.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/systemcmds/tests/test_mixer.cpp b/src/systemcmds/tests/test_mixer.cpp index c90fc6121d..c448a4ebb3 100644 --- a/src/systemcmds/tests/test_mixer.cpp +++ b/src/systemcmds/tests/test_mixer.cpp @@ -196,11 +196,11 @@ bool MixerTest::loadAllTest() if (strncmp(result->d_name, ".", 1) != 0) { char buf[PATH_MAX]; - (void)strncpy(&buf[0], MIXER_ONBOARD_PATH, sizeof(buf) - 1); - /* enforce null termination */ - buf[sizeof(buf) - 1] = '\0'; - (void)strncpy(&buf[strlen(MIXER_ONBOARD_PATH)], "/", 1); - (void)strncpy(&buf[strlen(MIXER_ONBOARD_PATH) + 1], result->d_name, sizeof(buf) - strlen(MIXER_ONBOARD_PATH) - 1); + + if (snprintf(buf, PATH_MAX, "%s/%s", MIXER_ONBOARD_PATH, result->d_name) >= PATH_MAX) { + PX4_ERR("mixer path too long %s", result->d_name); + return false; + } bool ret = load_mixer(buf, 0);