From 3b0489b1a33573ceac8d81a728a56a97d06830eb Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 13 Dec 2007 09:20:13 +0000 Subject: * string.c (rb_str_succ): should not enter infinite loop for non-ASCII, non-alphanumeric character at the bottom. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index bb12d5061..2ab808281 100644 --- a/string.c +++ b/string.c @@ -1811,6 +1811,7 @@ rb_str_succ(VALUE orig) VALUE str; char *sbeg, *s, *e; int c = -1; + unsigned int cc = 0; long n = 0, o = 0, l; char carry[ONIGENC_CODE_TO_MBC_MAXLEN]; @@ -1824,7 +1825,7 @@ rb_str_succ(VALUE orig) s = e = sbeg + RSTRING_LEN(str); while ((s = rb_enc_prev_char(sbeg, s, enc)) != 0) { - unsigned int cc = rb_enc_codepoint(s, e, enc); + cc = rb_enc_codepoint(s, e, enc); if (rb_enc_isalnum(cc, enc)) { if (isascii(cc)) { if ((c = succ_char(s)) == 0) break; @@ -1834,12 +1835,16 @@ rb_str_succ(VALUE orig) } n = s - sbeg; } + else { + break; + } } if (c == -1) { /* str contains no alnum */ c = '\001'; s = e; while ((s = rb_enc_prev_char(sbeg, e, enc)) != 0) { - unsigned int cc = rb_enc_codepoint(s, e, enc) + 1; + if (cc == 0) cc = rb_enc_codepoint(s, e, enc); + cc += 1; l = rb_enc_mbcput(cc, carry, enc); if (l > 0) { if (l == (o = e - s)) goto overlay; -- cgit