From 8d8ac30f08e4618e3ae06ffc6d52ef4cd932ce75 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 10 Jan 2014 09:11:10 +0000 Subject: [PATCH] fixed a bug of hanlding an empty string properly in str::isxxx functions --- qse/lib/awk/mod-str.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/qse/lib/awk/mod-str.c b/qse/lib/awk/mod-str.c index dadcd6e5..a8489ffb 100644 --- a/qse/lib/awk/mod-str.c +++ b/qse/lib/awk/mod-str.c @@ -183,7 +183,7 @@ static int is_class (qse_awk_rtx_t* rtx, qse_ctype_t ctype) qse_awk_val_t* a0; qse_char_t* str0; qse_size_t len0; - int tmp = 1; + int tmp; a0 = qse_awk_rtx_getarg (rtx, 0); @@ -198,17 +198,22 @@ static int is_class (qse_awk_rtx_t* rtx, qse_ctype_t ctype) if (str0 == QSE_NULL) return -1; } - - - while (len0 > 0) + if (len0 <= 0) tmp = 0; + else { - if (!qse_isctype(str0[--len0], ctype)) + tmp = 1; + do { - tmp = 0; - break; + len0--; + if (!qse_isctype(str0[len0], ctype)) + { + tmp = 0; + break; + } } + while (len0 > 0); + if (a0->type != QSE_AWK_VAL_STR) qse_awk_rtx_freemem (rtx, str0); } - if (a0->type != QSE_AWK_VAL_STR) qse_awk_rtx_freemem (rtx, str0); a0 = qse_awk_rtx_makeintval (rtx, tmp); if (a0 == QSE_NULL) return -1;