[Spice-commits] vdagent/file_xfer.cpp

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Apr 27 06:32:57 UTC 2020


 vdagent/file_xfer.cpp |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

New commits:
commit dd05463f9ba00a1071a2f51a252c0f968e574f96
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Dec 5 08:57:01 2019 +0000

    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 at redhat.com>

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;
         }


More information about the Spice-commits mailing list