mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-17 05:43:33 +08:00
Fix -Werror=format-truncation on GCC 7
Fix formatting Check snprintf return for error AND overflow
This commit is contained in:
committed by
Julian Oes
parent
407b403e68
commit
7929287f73
@@ -355,20 +355,27 @@ MavlinkFTP::_workList(PayloadHeader *payload, bool list_hidden)
|
||||
switch (result->d_type) {
|
||||
#ifdef __PX4_NUTTX
|
||||
|
||||
case DTYPE_FILE:
|
||||
case DTYPE_FILE: {
|
||||
#else
|
||||
case DT_REG:
|
||||
#endif
|
||||
// For files we get the file size as well
|
||||
direntType = kDirentFile;
|
||||
snprintf(buf, sizeof(buf), "%s/%s", dirPath, result->d_name);
|
||||
struct stat st;
|
||||
|
||||
if (stat(buf, &st) == 0) {
|
||||
fileSize = st.st_size;
|
||||
case DT_REG: {
|
||||
#endif
|
||||
// For files we get the file size as well
|
||||
direntType = kDirentFile;
|
||||
int ret = snprintf(buf, sizeof(buf), "%s/%s", dirPath, result->d_name);
|
||||
bool buf_is_ok = ((ret > 0) && (ret < sizeof(buf)));
|
||||
|
||||
if (buf_is_ok) {
|
||||
struct stat st;
|
||||
|
||||
if (stat(buf, &st) == 0) {
|
||||
fileSize = st.st_size;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
#ifdef __PX4_NUTTX
|
||||
|
||||
case DTYPE_DIRECTORY:
|
||||
@@ -397,7 +404,12 @@ MavlinkFTP::_workList(PayloadHeader *payload, bool list_hidden)
|
||||
|
||||
} else if (direntType == kDirentFile) {
|
||||
// Files send filename and file length
|
||||
snprintf(buf, sizeof(buf), "%s\t%d", result->d_name, fileSize);
|
||||
int ret = snprintf(buf, sizeof(buf), "%s\t%d", result->d_name, fileSize);
|
||||
bool buf_is_ok = ((ret > 0) && (ret < sizeof(buf)));
|
||||
|
||||
if (!buf_is_ok) {
|
||||
buf[sizeof(buf) - 1] = '\0';
|
||||
}
|
||||
|
||||
} else {
|
||||
// Everything else just sends name
|
||||
@@ -995,4 +1007,3 @@ void MavlinkFTP::send(const hrt_abstime t)
|
||||
_reply(&ftp_msg);
|
||||
} while (more_data);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user