From 8b69579ab32379e7855618852e15b33c2ca5da31 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Wed, 13 Nov 2013 21:33:13 +0200 Subject: [PATCH] fix a few compile errors and a potential case conversion bug in unicode --- src/duk_unicode_support.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/duk_unicode_support.c b/src/duk_unicode_support.c index 69430aac..ba37a2e9 100644 --- a/src/duk_unicode_support.c +++ b/src/duk_unicode_support.c @@ -634,13 +634,14 @@ static duk_codepoint_t slow_case_conversion(duk_hthread *thr, DUK_DDDPRINT("range: start_i=%d, start_o=%d, count=%d, skip=%d", (int) start_i, (int) start_o, (int) count, (int) skip); - tmp_cp = cp - start_i; - if (tmp_cp >= 0 && - tmp_cp < (duk_codepoint_t) count * (duk_codepoint_t) skip && - (tmp_cp % (duk_codepoint_t) skip) == 0) { - DUK_DDDPRINT("range matches input codepoint"); - cp = start_o + tmp_cp; - goto single; + if (cp >= start_i) { + tmp_cp = cp - start_i; /* always >= 0 */ + if (tmp_cp < (duk_codepoint_t) count * (duk_codepoint_t) skip && + (tmp_cp % (duk_codepoint_t) skip) == 0) { + DUK_DDDPRINT("range matches input codepoint"); + cp = start_o + tmp_cp; + goto single; + } } } } @@ -703,15 +704,13 @@ static duk_codepoint_t slow_case_conversion(duk_hthread *thr, static duk_signed_codepoint_t case_transform_helper(duk_hthread *thr, duk_hbuffer_dynamic *buf, - duk_signed_codepoint_t cp, + duk_codepoint_t cp, duk_signed_codepoint_t prev, duk_signed_codepoint_t next, duk_small_int_t uppercase, duk_small_int_t language) { duk_bitdecoder_ctx bd_ctx; - DUK_ASSERT(cp >= 0); - /* fast path for ASCII */ if (cp < 0x80UL) { /* FIXME: context sensitive rules exist for ASCII range too. @@ -823,7 +822,7 @@ void duk_unicode_case_convert_string(duk_hthread *thr, duk_small_int_t uppercase /* may generate any number of output codepoints */ case_transform_helper(thr, h_buf, - curr, + (duk_codepoint_t) curr, prev, next, uppercase, @@ -845,7 +844,7 @@ void duk_unicode_case_convert_string(duk_hthread *thr, duk_small_int_t uppercase */ duk_codepoint_t duk_unicode_re_canonicalize_char(duk_hthread *thr, duk_codepoint_t cp) { - duk_codepoint_t y; + duk_signed_codepoint_t y; y = case_transform_helper(thr, NULL, /* buf */