mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-06 15:28:52 +08:00
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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user