diff --git a/libraries/GCS_MAVLink/GCS_FTP.cpp b/libraries/GCS_MAVLink/GCS_FTP.cpp index f9098f4fd5..8ce03c23e6 100644 --- a/libraries/GCS_MAVLink/GCS_FTP.cpp +++ b/libraries/GCS_MAVLink/GCS_FTP.cpp @@ -579,7 +579,12 @@ int GCS_MAVLINK::gen_dir_entry(char *dest, size_t space, const char *path, const } if (is_file) { - const size_t full_path_len = strlen(path) + strnlen(entry->d_name, 256); // FIXME: Really should do better then just hardcoding 256 +#ifdef MAX_NAME_LEN + const uint8_t max_name_len = MIN(unsigned(MAX_NAME_LEN), 255U); +#else + const uint8_t max_name_len = 255U; +#endif + const size_t full_path_len = strlen(path) + strnlen(entry->d_name, max_name_len); char full_path[full_path_len + 2]; hal.util->snprintf(full_path, sizeof(full_path), "%s/%s", path, entry->d_name); struct stat st;