diff options
| author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-06-12 13:30:32 +0000 |
|---|---|---|
| committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-06-12 13:30:32 +0000 |
| commit | adc15cc997f3d1a3d067c77962437d291e73c1f8 (patch) | |
| tree | f7720444e28f6c87c4c97658a5e334d2c27dbf6f /sprintf.c | |
| parent | 00db6e744aa5056a96670eb03d374e0f5936afef (diff) | |
| download | ruby-adc15cc997f3d1a3d067c77962437d291e73c1f8.tar.gz ruby-adc15cc997f3d1a3d067c77962437d291e73c1f8.tar.xz ruby-adc15cc997f3d1a3d067c77962437d291e73c1f8.zip | |
* sprintf.c (rb_f_sprintf): adjust precision length to prevent
splitting multi-byte characters. [ruby-list:42389]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@10255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
| -rw-r--r-- | sprintf.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -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); |
