]> granicus.if.org Git - onig/commitdiff
define xsnprintf() macro for Windows platform
authorkosako <kosako@sofnec.co.jp>
Mon, 18 Apr 2016 04:44:27 +0000 (13:44 +0900)
committerkosako <kosako@sofnec.co.jp>
Mon, 18 Apr 2016 04:44:27 +0000 (13:44 +0900)
src/regerror.c
src/regint.h
src/regposerr.c
src/regversion.c

index 94a163ecdb53a60fe4b0c92534e5b0adb747aa86..ab24b4cbb4e265941cc6c23a8f8df51193fe9f82 100644 (file)
@@ -184,12 +184,12 @@ onig_error_code_to_format(int code)
 
 static void sprint_byte(char* s, unsigned int v)
 {
-  sprintf(s, "%02x", (v & 0377));
+  xsnprintf(s, 3, "%02x", (v & 0377));
 }
 
 static void sprint_byte_with_x(char* s, unsigned int v)
 {
-  sprintf(s, "\\x%02x", (v & 0377));
+  xsnprintf(s, 5, "\\x%02x", (v & 0377));
 }
 
 static int to_ascii(OnigEncoding enc, UChar *s, UChar *end,
index 7a39839c968c26ef8d229085f436e6580b954143..9d9d5dfdac2ba760124d7c77d19f05d0ff6e90bc 100644 (file)
 #if defined(_WIN32) && !defined(__GNUC__)
 #define xalloca     _alloca
 #define xvsnprintf  _vsnprintf
+#define xsnprintf   sprintf_s
 #else
 #define xalloca     alloca
 #define xvsnprintf  vsnprintf
+#define xsnprintf   snprintf
 #endif
 
 
index b5d7f6b40d11f61bafed76b5507c15185f81ddc5..c6db2e20efc35ff79b867ec2ec8dfcf3eaed0aa1 100644 (file)
 #  define ARG_UNUSED
 #endif
 
+#if defined(_WIN32) && !defined(__GNUC__)
+#define xsnprintf   sprintf_s
+#else
+#define xsnprintf   snprintf
+#endif
+
 static char* ESTRING[] = {
   NULL,
   "failed to match",                         /* REG_NOMATCH    */
@@ -83,7 +89,7 @@ regerror(int posix_ecode, const regex_t* reg ARG_UNUSED, char* buf,
     s = "";
   }
   else {
-    sprintf(tbuf, "undefined error code (%d)", posix_ecode);
+    xsnprintf(tbuf, sizeof(tbuf), "undefined error code (%d)", posix_ecode);
     s = tbuf;
   }
 
index 113fbaedc64494141cfa1912a5f88da61dcc3919..245a001b57b7ac3908af2d0740c73684ebf7b5f9 100644 (file)
@@ -28,7 +28,7 @@
  */
 
 #include "config.h"
-#include "oniguruma.h"
+#include "regint.h"
 #include <stdio.h>
 
 extern const char*
@@ -36,10 +36,10 @@ onig_version(void)
 {
   static char s[12];
 
-  sprintf(s, "%d.%d.%d",
-          ONIGURUMA_VERSION_MAJOR,
-          ONIGURUMA_VERSION_MINOR,
-          ONIGURUMA_VERSION_TEENY);
+  xsnprintf(s, sizeof(s), "%d.%d.%d",
+            ONIGURUMA_VERSION_MAJOR,
+            ONIGURUMA_VERSION_MINOR,
+            ONIGURUMA_VERSION_TEENY);
   return s;
 }
 
@@ -48,9 +48,10 @@ onig_copyright(void)
 {
   static char s[58];
 
-  sprintf(s, "Oniguruma %d.%d.%d : Copyright (C) 2002-2008 K.Kosako",
-          ONIGURUMA_VERSION_MAJOR,
-          ONIGURUMA_VERSION_MINOR,
-          ONIGURUMA_VERSION_TEENY);
+  xsnprintf(s, sizeof(s),
+            "Oniguruma %d.%d.%d : Copyright (C) 2002-2016 K.Kosako",
+            ONIGURUMA_VERSION_MAJOR,
+            ONIGURUMA_VERSION_MINOR,
+            ONIGURUMA_VERSION_TEENY);
   return s;
 }