summaryrefslogtreecommitdiff
path: root/cord/cordprnt.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2016-10-28 09:35:33 +0300
committerIvan Maidanski <ivmai@mail.ru>2016-10-28 10:02:12 +0300
commitc10a1d900afabeaf1c8c2f7011bed31d2c572f02 (patch)
treeea0eec399785fa0c498b1aa4117de0d5523a2ebc /cord/cordprnt.c
parent311a0fceb7a6e81da99547f74d520f0ebf43c5ff (diff)
downloadbdwgc-c10a1d900afabeaf1c8c2f7011bed31d2c572f02.tar.gz
Eliminate 'unsafe vsprintf is deprecated' compiler warning
Replacement of vsprintf to vsnprintf (or similar) if available. Note that no buffer overflow occurs in CORD_vsprintf as buf is allocated dynamically based on format string. * cord/cordprnt.c (GC_VSNPRINTF): New macro (the definition is copied from misc.c). * cord/cordprnt.c (CORD_vsprintf): Replace vsprintf(buf,...) call with GC_VSNPRINTF(buf,max_size+1,...).
Diffstat (limited to 'cord/cordprnt.c')
-rw-r--r--cord/cordprnt.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/cord/cordprnt.c b/cord/cordprnt.c
index d3a85da6..70bad9cd 100644
--- a/cord/cordprnt.c
+++ b/cord/cordprnt.c
@@ -172,6 +172,20 @@ static int extract_conv_spec(CORD_pos source, char *buf,
return(result);
}
+#if defined(DJGPP) || defined(__STRICT_ANSI__)
+ /* vsnprintf is missing in DJGPP (v2.0.3) */
+# define GC_VSNPRINTF(buf, bufsz, format, args) vsprintf(buf, format, args)
+#elif defined(_MSC_VER)
+# ifdef MSWINCE
+ /* _vsnprintf is deprecated in WinCE */
+# define GC_VSNPRINTF StringCchVPrintfA
+# else
+# define GC_VSNPRINTF _vsnprintf
+# endif
+#else
+# define GC_VSNPRINTF vsnprintf
+#endif
+
int CORD_vsprintf(CORD * out, CORD format, va_list args)
{
CORD_ec result;
@@ -328,7 +342,8 @@ int CORD_vsprintf(CORD * out, CORD format, va_list args)
res = -1;
}
if (0 == res)
- res = vsprintf(buf, conv_spec, vsprintf_args);
+ res = GC_VSNPRINTF(buf, max_size + 1, conv_spec,
+ vsprintf_args);
# if defined(CPPCHECK) || defined(__va_copy) \
|| (defined(__GNUC__) && !defined(__DJGPP__) \
&& !defined(__EMX__))