summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-12 13:30:32 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-12 13:30:32 +0000
commita2f6c40d2daeaa922a7075007c6a30a88d2630ad (patch)
treef7720444e28f6c87c4c97658a5e334d2c27dbf6f /sprintf.c
parent3a1f31129e4f63397937c3d40a5139826d2e553f (diff)
* sprintf.c (rb_f_sprintf): adjust precision length to prevent
splitting multi-byte characters. [ruby-list:42389] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/sprintf.c b/sprintf.c
index 5e85d95..3c0bc5c 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -13,6 +13,7 @@
**********************************************************************/
#include "ruby.h"
+#include "re.h"
#include <ctype.h>
#include <math.h>
@@ -413,6 +414,23 @@ rb_f_sprintf(argc, argv)
len = prec;
}
}
+ {
+ char *s, *send;
+ long l;
+
+ s = RSTRING(str)->ptr;
+ send = s + RSTRING(str)->len;
+ l = 0;
+ while (s < send) {
+ long n = mbclen(*s);
+ if (l + n > len) {
+ len = l;
+ break;
+ }
+ l += n;
+ s += n;
+ }
+ }
if (flags&FWIDTH) {
if (width > len) {
CHECK(width);