From: kosako Date: Mon, 18 Apr 2016 04:44:27 +0000 (+0900) Subject: define xsnprintf() macro for Windows platform X-Git-Tag: v6.0.0^2~47 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=21cc66e990fe395cdf138c1af9885b74387f6867;p=onig define xsnprintf() macro for Windows platform --- diff --git a/src/regerror.c b/src/regerror.c index 94a163e..ab24b4c 100644 --- a/src/regerror.c +++ b/src/regerror.c @@ -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, diff --git a/src/regint.h b/src/regint.h index 7a39839..9d9d5df 100644 --- a/src/regint.h +++ b/src/regint.h @@ -129,9 +129,11 @@ #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 diff --git a/src/regposerr.c b/src/regposerr.c index b5d7f6b..c6db2e2 100644 --- a/src/regposerr.c +++ b/src/regposerr.c @@ -42,6 +42,12 @@ # 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; } diff --git a/src/regversion.c b/src/regversion.c index 113fbae..245a001 100644 --- a/src/regversion.c +++ b/src/regversion.c @@ -28,7 +28,7 @@ */ #include "config.h" -#include "oniguruma.h" +#include "regint.h" #include 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; }