[Spice-devel] [vdagent-win PATCH V3 10/11] Fix Visual Studio compiler warning (strcat and sscanf)

Uri Lublin uril at redhat.com
Tue Dec 30 08:20:56 PST 2014


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.
---
 common/vdcommon.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

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 {
-- 
1.7.1



More information about the Spice-devel mailing list