Ver código fonte

replace sprintf with its safer version in windows platform

use platform specific version of sprintf

add MinGW macro to specify sprintf_s version using

fixing tiny header file defined macro problem

fixing tiny header file defined macro problem v2.0

leaving linux version as sprintf
Reza Ebrahimi 10 anos atrás
pai
commit
c9bce505f1
1 arquivos alterados com 13 adições e 2 exclusões
  1. 13 2
      src/ua_types.c

+ 13 - 2
src/ua_types.c

@@ -5,6 +5,10 @@
 
 #include "pcg_basic.h"
 
+#ifdef _MSC_VER
+#include <strsafe.h>
+#endif
+
 /*****************/
 /* Helper Macros */
 /*****************/
@@ -228,8 +232,15 @@ UA_StatusCode UA_DateTime_toString(UA_DateTime atime, UA_String *timeString) {
     timeString->length = 31;
 
     UA_DateTimeStruct tSt = UA_DateTime_toStruct(atime);
-    sprintf((char*)timeString->data, "%02d/%02d/%04d %02d:%02d:%02d.%03d.%03d.%03d", tSt.month, tSt.day, tSt.year,
-            tSt.hour, tSt.min, tSt.sec, tSt.milliSec, tSt.microSec, tSt.nanoSec);
+#ifdef _MSC_VER
+    StringCchPrintf((char*)timeString->data, (size_t)timeString->length,
+        "%02d/%02d/%04d %02d:%02d:%02d.%03d.%03d.%03d",
+        tSt.month, tSt.day, tSt.year, tSt.hour, tSt.min, tSt.sec, tSt.milliSec, tSt.microSec, tSt.nanoSec);
+#else
+    sprintf((char*)timeString->data,
+        "%02d/%02d/%04d %02d:%02d:%02d.%03d.%03d.%03d", 
+        tSt.month, tSt.day, tSt.year, tSt.hour, tSt.min, tSt.sec, tSt.milliSec, tSt.microSec, tSt.nanoSec);
+#endif
     return UA_STATUSCODE_GOOD;
 }