[Spice-commits] common/vdcommon.cpp common/vdcommon.h

Frediano Ziglio fziglio at kemper.freedesktop.org
Wed Aug 10 10:19:39 UTC 2016


 common/vdcommon.cpp |   16 ++++++++++++++++
 common/vdcommon.h   |    8 ++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)

New commits:
commit 9ab74bb67ae48ae5e11b7f637c3ad7428bf46d9f
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Wed Aug 10 08:17:05 2016 +0100

    Fix swprintf_s call under MingW
    
    For some reason this call does not behave correctly.
    This was causing vdservice to fail to run the agent if compiled
    with MingW.
    Provide a proper swprintf_s replacement.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Victor Toso <victortoso at redhat.com>

diff --git a/common/vdcommon.cpp b/common/vdcommon.cpp
index 4f80a2c..f5311e3 100644
--- a/common/vdcommon.cpp
+++ b/common/vdcommon.cpp
@@ -15,6 +15,8 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#include <stdarg.h>
+
 #include "vdcommon.h"
 
 int supported_system_version()
@@ -76,3 +78,17 @@ errno_t vdagent_strcpy_s(char *strDestination,
     return 0;
 }
 #endif
+
+#ifndef HAVE_SWPRINTF_S
+int vdagent_swprintf_s(wchar_t *buf, size_t len, const wchar_t *format, ...)
+{
+    va_list ap;
+    va_start(ap, format);
+    int res = _vsnwprintf(buf, len, format, ap);
+    va_end(ap);
+    if ((res < 0 || (unsigned) res >= len) && len > 0) {
+        buf[0] = 0;
+    }
+    return res;
+}
+#endif
diff --git a/common/vdcommon.h b/common/vdcommon.h
index 93bb673..c5f6e93 100644
--- a/common/vdcommon.h
+++ b/common/vdcommon.h
@@ -62,8 +62,6 @@ typedef CRITICAL_SECTION mutex_t;
  * those functions are not required to be in that dll on the guest.
  */
 #ifdef OLDMSVCRT
-#define swprintf_s(buf, sz, format...) swprintf(buf, format)
-
 #ifndef _ftime_s
 #define _ftime_s(timeb) _ftime(timeb)
 #endif
@@ -72,6 +70,7 @@ typedef CRITICAL_SECTION mutex_t;
 #ifdef _MSC_VER // compiling with Visual Studio
 #define HAVE_STRCAT_S 1
 #define HAVE_STRCPY_S 1
+#define HAVE_SWPRINTF_S 1
 #endif
 
 #ifdef HAVE_STRCAT_S
@@ -90,6 +89,11 @@ errno_t vdagent_strcpy_s(char *strDestination,
                          const char *strSource);
 #endif
 
+#ifndef HAVE_SWPRINTF_S
+int vdagent_swprintf_s(wchar_t *buf, size_t len, const wchar_t *format, ...);
+#define swprintf_s vdagent_swprintf_s
+#endif
+
 #ifdef _MSC_VER // compiling with Visual Studio
 #define snprintf         sprintf_s
 #define sscanf           sscanf_s


More information about the Spice-commits mailing list