[Spice-commits] 11 commits - common/vdcommon.h vdagent/as_user.cpp vdagent/file_xfer.cpp vdagent/file_xfer.h vdagent/vdagent.cpp

Uri Lublin uril at kemper.freedesktop.org
Mon Jan 12 06:08:07 PST 2015


 common/vdcommon.h     |   28 ++++++++++++++++++++++++++--
 vdagent/as_user.cpp   |    4 ++--
 vdagent/file_xfer.cpp |   11 +++++++++--
 vdagent/file_xfer.h   |    2 ++
 vdagent/vdagent.cpp   |    4 ++--
 5 files changed, 41 insertions(+), 8 deletions(-)

New commits:
commit d1c8d152f4c710384be27f7d346b653a9a31ed24
Author: Uri Lublin <uril at redhat.com>
Date:   Mon Dec 29 17:46:28 2014 +0200

    g_key_get_string: use size_t for pointer difference
    
    The 64 bit Visual Studio build complains that:
      .\file_xfer.cpp(223) : warning C4244:
        '=' : conversion from '__int64' to 'unsigned int', possible loss of data

diff --git a/vdagent/file_xfer.cpp b/vdagent/file_xfer.cpp
index 3aad4ac..8d7c86c 100644
--- a/vdagent/file_xfer.cpp
+++ b/vdagent/file_xfer.cpp
@@ -205,7 +205,7 @@ bool FileXfer::g_key_get_string(char* data, const char* group, const char* key,
 {
     char group_pfx[G_KEY_MAX_LEN], key_pfx[G_KEY_MAX_LEN];
     char *group_pos, *key_pos, *next_group_pos, *start, *end;
-    unsigned len;
+    size_t len;
 
     snprintf(group_pfx, sizeof(group_pfx), "[%s]", group);
     if (!(group_pos = strstr((char*)data, group_pfx))) return false;
commit e04ffbc6080b07ca6edcab06c539a90496c78805
Author: Uri Lublin <uril at redhat.com>
Date:   Mon Dec 29 18:22:24 2014 +0200

    Fix Visual Studio compiler warning (strcat and sscanf)
    
    This is a follow-up to commits 492ee05a6b and 4b9e9b1d28
    
    Visual Studio complains:
      .\file_xfer.cpp(90) : warning C4996: 'strcat': This function or variable
      may be unsafe. Consider using strcat_s instead.
      To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
      See online help for details.
    
    And a similar complain for sscanf.
    
    Replace them with the secure function when compiling with Visual Studio.
    Note that the size provided is sizeof(d), which means all calls to
    sscanf and strcat must be done with the first param (destination) being
    an array and not a pointer.

diff --git a/common/vdcommon.h b/common/vdcommon.h
index f285175..af270db 100644
--- a/common/vdcommon.h
+++ b/common/vdcommon.h
@@ -71,6 +71,8 @@ typedef CRITICAL_SECTION mutex_t;
 #ifdef _MSC_VER // compiling with Visual Studio
 #define snprintf         sprintf_s
 #define strncpy(d,s,n)   strcpy_s(s, __min(n+1, sizeof(d)), s)
+#define strcat(d,s)      strcat_s(d, sizeof(d), s)
+#define sscanf           sscanf_s
 #endif
 
 enum SystemVersion {
commit d752a5b6e0cc41879feeebc05e751d8425727671
Author: Uri Lublin <uril at redhat.com>
Date:   Tue Nov 25 18:48:08 2014 +0200

    Fix Visual Studio compiler warning (strncpy)
    
    Visual Studio complains:
      vdagent\file_xfer.h(28) : warning C4996: 'strncpy': This function or variable may
      Consider using strncpy_s instead.
      To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
      See online help for details.
    
    Replace strncpy with strcpy_s when building with Visual Studio.
    Adjust parameter order and difference in meaning of length:
    - length param is last in strncpy and second in strcpy_s
    - many calls to strncpy are given length param n-1, as
      strncpy does not guarantee that destination ends with '\0'
    - it's safer to set length param not larger than sizeof(d)
      (assuming d is an array not a pointer)
    
    Trying to use strcpy_s for both Visual Studio and mingw
    failed as strcpy_s is missing from the default msvcrt.dll
    on WinXP (See OLDMSVCRT in common/vdcommon.h).

diff --git a/common/vdcommon.h b/common/vdcommon.h
index 568e3ba..f285175 100644
--- a/common/vdcommon.h
+++ b/common/vdcommon.h
@@ -70,6 +70,7 @@ typedef CRITICAL_SECTION mutex_t;
 
 #ifdef _MSC_VER // compiling with Visual Studio
 #define snprintf         sprintf_s
+#define strncpy(d,s,n)   strcpy_s(s, __min(n+1, sizeof(d)), s)
 #endif
 
 enum SystemVersion {
diff --git a/vdagent/file_xfer.h b/vdagent/file_xfer.h
index b506f59..07a6808 100644
--- a/vdagent/file_xfer.h
+++ b/vdagent/file_xfer.h
@@ -25,6 +25,8 @@ 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..
+        //        currently the only user is FileXfer::handle_start
+        //        which verifies that strlen(_name) < MAX_PATH
         strncpy(name, _name, sizeof(name) - 1);
     }
     HANDLE handle;
commit c76e541bbad9243043733004c95ee5955a9560dd
Author: Uri Lublin <uril at redhat.com>
Date:   Tue Nov 25 18:12:32 2014 +0200

    Fix building with Visual Studio (snprintf)
    
    This commit is an addition to 4b9e9b1d28ea7eaec44ff73e2f91c4064986b12a
    
    Building with Visual Studio breaks as snprintf is not implemented:
      vdagent\file_xfer.cpp(198) : error C3861: 'snprintf': identifier not found
    
    Replace it with sprintf_s for Visual Studio.
    
    Trying to use sprintf_s for both Visual Studio and mingw
    failed for mingw64 (build succeeds but runtime error appears).

diff --git a/common/vdcommon.h b/common/vdcommon.h
index 74496f1..568e3ba 100644
--- a/common/vdcommon.h
+++ b/common/vdcommon.h
@@ -68,6 +68,10 @@ typedef CRITICAL_SECTION mutex_t;
 #endif
 #endif /* OLDMSVCRT */
 
+#ifdef _MSC_VER // compiling with Visual Studio
+#define snprintf         sprintf_s
+#endif
+
 enum SystemVersion {
     SYS_VER_UNSUPPORTED,
     SYS_VER_WIN_XP_CLASS, // also Server 2003/R2
commit 88b9b74d95fdb1fb680742e586c1a29ed127da52
Author: Uri Lublin <uril at redhat.com>
Date:   Mon Mar 24 19:02:38 2014 +0200

    Fix building with Visual Studio (inttypes.h)
    
    As a followup of commit 462295d9f84658aa7.
    
    Building with Visual Studio, fails as there is no inttypes.h file:
      vdagent\file_xfer.cpp(21) : fatal error C1083: Cannot open
      include file: 'inttypes.h': No such file or directory
    
    This commit prevents including inttypes.h when building with Visual Studio,
    and defines PRIu64 that is defined in inttypes.h for mingw compiler.

diff --git a/vdagent/file_xfer.cpp b/vdagent/file_xfer.cpp
index f8cd07f..3aad4ac 100644
--- a/vdagent/file_xfer.cpp
+++ b/vdagent/file_xfer.cpp
@@ -18,7 +18,14 @@
 #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>
+#endif // compiler specific definitions
+
 #include <stdio.h>
 #include "file_xfer.h"
 #include "as_user.h"
commit cf747c07e625b5bbc3c1859d7fa278e45e97ef96
Author: Uri Lublin <uril at redhat.com>
Date:   Tue Nov 11 13:07:47 2014 +0200

    vdcommon.h: consolidate defines under OLDMSVCRT

diff --git a/common/vdcommon.h b/common/vdcommon.h
index 6ab18c6..74496f1 100644
--- a/common/vdcommon.h
+++ b/common/vdcommon.h
@@ -62,13 +62,11 @@ typedef CRITICAL_SECTION mutex_t;
  */
 #ifdef OLDMSVCRT
 #define swprintf_s(buf, sz, format...) swprintf(buf, format)
-#endif
 
-#ifdef OLDMSVCRT
 #ifndef _ftime_s
 #define _ftime_s(timeb) _ftime(timeb)
 #endif
-#endif
+#endif /* OLDMSVCRT */
 
 enum SystemVersion {
     SYS_VER_UNSUPPORTED,
commit c678c4f26b6139b64689c6785ddf729134697f58
Author: Uri Lublin <uril at redhat.com>
Date:   Thu Oct 23 09:23:09 2014 -0400

    vdcommon.h: do not redefine _ftime_s
    
    Fixes the following error:
    ====
    In file included from vdagent/vdagent.cpp:18:0:
    ./common/vdcommon.h:51:0: warning: "_ftime_s" redefined
     #define _ftime_s(timeb) _ftime(timeb)
     ^
    In file included from /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/timeb.h:124:0,
    =====

diff --git a/common/vdcommon.h b/common/vdcommon.h
index 3d0f794..6ab18c6 100644
--- a/common/vdcommon.h
+++ b/common/vdcommon.h
@@ -65,8 +65,10 @@ typedef CRITICAL_SECTION mutex_t;
 #endif
 
 #ifdef OLDMSVCRT
+#ifndef _ftime_s
 #define _ftime_s(timeb) _ftime(timeb)
 #endif
+#endif
 
 enum SystemVersion {
     SYS_VER_UNSUPPORTED,
commit a6383f29dc0788a401b64ca2f3aca07190d49e2b
Author: Uri Lublin <uril at redhat.com>
Date:   Wed Nov 5 10:20:30 2014 -0500

    vdcommon.h: add comment about OLDMSVCRT

diff --git a/common/vdcommon.h b/common/vdcommon.h
index 177721c..3d0f794 100644
--- a/common/vdcommon.h
+++ b/common/vdcommon.h
@@ -43,6 +43,23 @@ typedef CRITICAL_SECTION mutex_t;
 #define ALIGN_VC __declspec (align(1))
 #endif
 
+/*
+ * Note: OLDMSVCRT, which is defined (in the Makefile) for mingw builds, and
+ * is not defined for Visual Studio builds.
+ *
+ * On Windows XP some those functions are missing from the msvcrt.dll
+ * When compiled with mingw, the program fails to run due to missing functions.
+ * One can link to a newer runtime dll, e.g. msvcr100.dll, but that would
+ * require installing that DLL on the guest. That can be done by downloading
+ * and installing Microsoft Visual C++ 2010 Redistributable Package.
+ * (same for 110.dll and 2012 Redistributable Package, etc).
+ *
+ * Since we do not want to add this dependency, we use functions that are
+ * available in msvcrt.dll (and use define in the code).
+ *
+ * Currently Visual Studio builds are built with /MT (static mode) such that
+ * those functions are not required to be in that dll on the guest.
+ */
 #ifdef OLDMSVCRT
 #define swprintf_s(buf, sz, format...) swprintf(buf, format)
 #endif
commit dd53b1766e80aaa6fcdf593e1e2f6f005704efbd
Author: Uri Lublin <uril at redhat.com>
Date:   Thu Oct 23 09:44:08 2014 -0400

    vdagent::handle_max_clipboard fix vd_printf format
    
    Using unsigned long to print a size_t.

diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
index aa44383..efce981 100644
--- a/vdagent/vdagent.cpp
+++ b/vdagent/vdagent.cpp
@@ -889,8 +889,8 @@ bool VDAgent::handle_display_config(VDAgentDisplayConfig* display_config, uint32
 bool VDAgent::handle_max_clipboard(VDAgentMaxClipboard *msg, uint32_t size)
 {
     if (size != sizeof(VDAgentMaxClipboard)) {
-        vd_printf("VDAgentMaxClipboard: unexpected msg size %u (expected %u)",
-                  size, sizeof(VDAgentMaxClipboard));
+        vd_printf("VDAgentMaxClipboard: unexpected msg size %u (expected %lu)",
+                  size, (unsigned long)sizeof(VDAgentMaxClipboard));
         return false;
     }
     vd_printf("Set max clipboard size: %d", msg->max);
commit 8a28f878b95f1edf28d02542587393382fbe5e2e
Author: Uri Lublin <uril at redhat.com>
Date:   Mon Mar 24 19:02:43 2014 +0200

    vdagent: as_user: reorder initialization to make mingw-gcc happy
    
    Fixes compiler warning that starts with:
    
    In file included from vdagent/as_user.cpp:19:0:
    vdagent/as_user.h: In constructor 'AsUser::AsUser(DWORD)':
    vdagent/as_user.h:35:10: warning: 'AsUser::_started' will be initialized after [-Wreorder]
         bool _started;

diff --git a/vdagent/as_user.cpp b/vdagent/as_user.cpp
index d2d6c58..c8016da 100644
--- a/vdagent/as_user.cpp
+++ b/vdagent/as_user.cpp
@@ -21,9 +21,9 @@
 #include <wtsapi32.h>
 
 AsUser::AsUser(DWORD session_id):
-    _started(false),
     _session_id(session_id),
-    _token(INVALID_HANDLE_VALUE)
+    _token(INVALID_HANDLE_VALUE),
+    _started(false)
 {
 }
 
commit eb276f4b45f063273373d2379fae5d66c3a60ec5
Author: Uri Lublin <uril at redhat.com>
Date:   Mon Mar 24 19:02:42 2014 +0200

    Fix compiler warning (missing backslash in FileXfer::handle_start)
    
    Visual Studio complains:
    vdagent\file_xfer.cpp(85) : warning C4129: '%' : unrecognized character escape sequence
    
    Replace "%s\%s" with "%s\\%s"

diff --git a/vdagent/file_xfer.cpp b/vdagent/file_xfer.cpp
index 208303f..f8cd07f 100644
--- a/vdagent/file_xfer.cpp
+++ b/vdagent/file_xfer.cpp
@@ -76,7 +76,7 @@ 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;
     }
 


More information about the Spice-commits mailing list