mixer_test: use snprintf instead of strncpy to fix compiler warning

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);
This commit is contained in:
Beat Küng
2018-05-09 07:59:46 +02:00
parent 289e618b6c
commit f2092dd690
+5 -5
View File
@@ -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);