summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2019-12-05 08:57:01 +0000
committerFrediano Ziglio <freddy77@gmail.com>2020-04-24 11:22:37 +0100
commitdd05463f9ba00a1071a2f51a252c0f968e574f96 (patch)
treeef6144d19ac0875bd1258503ebe94789a1168c76
parentb4776f4291bb36c2814b3d2affe49af041fb133a (diff)
Use SPICE_N_ELEMENTS instead of a constant for file_path size
Allows to easily change the size if needed Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
-rw-r--r--vdagent/file_xfer.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/vdagent/file_xfer.cpp b/vdagent/file_xfer.cpp
index 51f7d34..eb53c46 100644
--- a/vdagent/file_xfer.cpp
+++ b/vdagent/file_xfer.cpp
@@ -105,6 +105,7 @@ void FileXfer::handle_start(VDAgentFileXferStartMessage* start,
return;
}
+ static_assert(SPICE_N_ELEMENTS(file_path) >= MAX_PATH, "file_path too small");
if (!get_download_directory(file_path)) {
return;
}
@@ -123,7 +124,7 @@ void FileXfer::handle_start(VDAgentFileXferStartMessage* start,
wlen = _tcslen(file_path);
// make sure we have enough space
// (1 char for separator, 1 char for filename and 1 char for NUL terminator)
- if (wlen + 3 >= MAX_PATH) {
+ if (wlen + 3 >= SPICE_N_ELEMENTS(file_path)) {
vd_printf("error: file too long %ls\\%s", file_path, file_name);
return;
}
@@ -145,7 +146,8 @@ void FileXfer::handle_start(VDAgentFileXferStartMessage* start,
snprintf(dest_filename, sizeof(dest_filename),
"%.*s (%d)%s", int(extension - file_name), file_name, attempt, extension);
}
- if ((MultiByteToWideChar(CP_UTF8, 0, dest_filename, -1, file_path + wlen, MAX_PATH - wlen)) == 0) {
+ if ((MultiByteToWideChar(CP_UTF8, 0, dest_filename, -1,
+ file_path + wlen, SPICE_N_ELEMENTS(file_path) - wlen)) == 0) {
vd_printf("failed converting file_name:%s to WideChar", dest_filename);
return;
}