[vdagent-win 1/2] vdagent: file-xfer: fix compilation warnings when building with Visual Studio

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch reverts some of the changes made in commit
4b9e9b1d28ea7eaec44ff73e2f91c4064986b12a
---
 vdagent/file_xfer.cpp | 23 +++++++++++++++++------
 vdagent/file_xfer.h   |  2 +-
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/vdagent/file_xfer.cpp b/vdagent/file_xfer.cpp
index e402eb2..cdb5654 100644
--- a/vdagent/file_xfer.cpp
+++ b/vdagent/file_xfer.cpp
@@ -18,7 +18,18 @@
 #include <shlobj.h>
 #define __STDC_FORMAT_MACROS
 #define __USE_MINGW_ANSI_STDIO 1
+
+// compiler specific definitions
+#ifdef _MSC_VER // compiling with Visual Studio
+#define PRIu64 "I64u"
+#else // compiling with mingw
 #include <inttypes.h>
+#define sscanf_s sscanf
+//#define sprintf_s snprintf /* apprently sprintf_s is implemented in mingw */
+#define strcpy_s(d, n, s) strncpy(d, s, n)
+#define strcat_s(d, n, s) strncat(d, s, n)
+#endif // compiler specific definitions
+
 #include <stdio.h>
 #include "file_xfer.h"
 #include "as_user.h"
@@ -75,12 +86,12 @@ void FileXfer::handle_start(VDAgentFileXferStartMessage* start,
     }

     if (strlen(file_path) + strlen(file_name) + 1 >= MAX_PATH) {
-        vd_printf("error: file too long %s\%s", file_path, file_name);
+        vd_printf("error: file too long %s\\%s", file_path, file_name);
         return;
     }

-    strcat(file_path, "\\");
-    strcat(file_path, file_name);
+    strcat_s(file_path, MAX_PATH, "\\");
+    strcat_s(file_path, MAX_PATH, file_name);
     handle = CreateFileA(file_path, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
     if (handle == INVALID_HANDLE_VALUE) {
         vd_printf("failed creating %s %lu", file_path, GetLastError());
@@ -188,10 +199,10 @@ bool FileXfer::g_key_get_string(char* data, const char* group, const char* key,
     char *group_pos, *key_pos, *next_group_pos, *start, *end;
     unsigned len;

-    snprintf(group_pfx, sizeof(group_pfx), "[%s]", group);
+    sprintf_s(group_pfx, sizeof(group_pfx), "[%s]", group);
     if (!(group_pos = strstr((char*)data, group_pfx))) return false;

-    snprintf(key_pfx, sizeof(key_pfx), "\n%s=", key);
+    sprintf_s(key_pfx, sizeof(key_pfx), "\n%s=", key);
     if (!(key_pos = strstr(group_pos, key_pfx))) return false;

     next_group_pos = strstr(group_pos + strlen(group_pfx), "[");
@@ -216,5 +227,5 @@ bool FileXfer::g_key_get_uint64(char* data, const char* group, const char* key,

     if (!g_key_get_string(data, group, key, str, sizeof(str)))
         return false;
-    return !!sscanf(str, "%" PRIu64, value);
+    return !!sscanf_s(str, "%" PRIu64, value);
 }
diff --git a/vdagent/file_xfer.h b/vdagent/file_xfer.h
index b506f59..2ffc320 100644
--- a/vdagent/file_xfer.h
+++ b/vdagent/file_xfer.h
@@ -25,7 +25,7 @@ typedef struct ALIGN_VC FileXferTask {
     FileXferTask(HANDLE _handle, uint64_t _size, char* _name):
     handle(_handle), size(_size), pos(0) {
         // FIXME: should raise an error if name is too long..
-        strncpy(name, _name, sizeof(name) - 1);
+        strcpy_s(name, sizeof(name) -1, _name);
     }
     HANDLE handle;
     uint64_t size;
-- 
1.8.5.3

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]