aboutsummaryrefslogtreecommitdiffstats
path: root/sprintf.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-22 03:05:20 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-22 03:05:20 +0000
commit9f3b77e43571744e04f2853e5e37671db2a7ddd7 (patch)
treeedd09e0e5530a5ad7300a96b8344dbcd3a7079cd /sprintf.c
parent0f6e6c8bbc4dd37868336019669582059edfda3f (diff)
downloadruby-9f3b77e43571744e04f2853e5e37671db2a7ddd7.tar.gz
* configure.in (mingw): no longer uses snprintf and vsnprintf of
msvcrt. * win32/win32.c (rb_w32_vsnprintf, rb_w32_snprintf): removed. * win32/Makefile.sub (config.h): vsnprintf exists in VC7 or later. * win32/mkexports.rb (Exports#initialize): aliases rb_w32_vsnprintf and rb_w32_snprintf for binary compatibility. * sprintf.c (rb_str_format): uses snprintf instead of sprintf. * numeric.c (flo_to_s, rb_num2long, rb_num2ll): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20909 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/sprintf.c b/sprintf.c
index 23671e6b93..1195f9b17b 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -25,7 +25,7 @@
#define BITSPERDIG (SIZEOF_BDIGITS*CHAR_BIT)
#define EXTENDSIGN(n, l) (((~0 << (n)) >> (((n)*(l)) % BITSPERDIG)) & ~(~0 << (n)))
-static void fmt_setup(char*,int,int,int,int);
+static void fmt_setup(char*,size_t,int,int,int,int);
static char*
remove_sign_bits(char *str, int base)
@@ -800,8 +800,8 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
sc = ' ';
width--;
}
- sprintf(fbuf, "%%l%c", c);
- sprintf(nbuf, fbuf, v);
+ snprintf(fbuf, sizeof(fbuf), "%%l%c", c);
+ snprintf(nbuf, sizeof(nbuf), fbuf, v);
s = nbuf;
}
else {
@@ -809,8 +809,8 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
if (v < 0) {
dots = 1;
}
- sprintf(fbuf, "%%l%c", *p == 'X' ? 'x' : *p);
- sprintf(++s, fbuf, v);
+ snprintf(fbuf, sizeof(fbuf), "%%l%c", *p == 'X' ? 'x' : *p);
+ snprintf(++s, sizeof(nbuf) - 1, fbuf, v);
if (v < 0) {
char d = 0;
@@ -980,7 +980,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
need = width;
CHECK(need);
- sprintf(&buf[blen], "%*s", need, "");
+ snprintf(&buf[blen], need, "%*s", need, "");
if (flags & FMINUS) {
if (!isnan(fval) && fval < 0.0)
buf[blen++] = '-';
@@ -1004,7 +1004,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
break;
}
- fmt_setup(fbuf, *p, flags, width, prec);
+ fmt_setup(fbuf, sizeof(fbuf), *p, flags, width, prec);
need = 0;
if (*p != 'e' && *p != 'E') {
i = INT_MIN;
@@ -1018,7 +1018,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
need += 20;
CHECK(need);
- sprintf(&buf[blen], fbuf, fval);
+ snprintf(&buf[blen], need, fbuf, fval);
blen += strlen(&buf[blen]);
}
break;
@@ -1041,8 +1041,9 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
}
static void
-fmt_setup(char *buf, int c, int flags, int width, int prec)
+fmt_setup(char *buf, size_t size, int c, int flags, int width, int prec)
{
+ char *end = buf + size;
*buf++ = '%';
if (flags & FSHARP) *buf++ = '#';
if (flags & FPLUS) *buf++ = '+';
@@ -1051,12 +1052,12 @@ fmt_setup(char *buf, int c, int flags, int width, int prec)
if (flags & FSPACE) *buf++ = ' ';
if (flags & FWIDTH) {
- sprintf(buf, "%d", width);
+ snprintf(buf, end - buf, "%d", width);
buf += strlen(buf);
}
if (flags & FPREC) {
- sprintf(buf, ".%d", prec);
+ snprintf(buf, end - buf, ".%d", prec);
buf += strlen(buf);
}
@@ -1084,7 +1085,15 @@ fmt_setup(char *buf, int c, int flags, int width, int prec)
#undef snprintf
#define FLOATING_POINT 1
#define BSD__dtoa ruby_dtoa
+#undef HAVE_VSNPRINTF
+#undef HAVE_SNPRINTF
+#if _MSC_VER >= 1300
+#pragma warning(disable: 4273)
+#endif
#include "missing/vsnprintf.c"
+#if _MSC_VER >= 1300
+#pragma warning(default: 4273)
+#endif
static int
ruby__sfvwrite(register rb_printf_buffer *fp, register struct __suio *uio)