From: K.Kosako Date: Tue, 9 Oct 2018 04:57:13 +0000 (+0900) Subject: fix s == NULL case in MATCH_DEBUG_OUT() X-Git-Tag: v6.9.1~18^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=114a10ec8532d75aeef0c9b887ed28d66267599d;p=onig fix s == NULL case in MATCH_DEBUG_OUT() --- diff --git a/src/regexec.c b/src/regexec.c index e4ed2ae..0d06603 100644 --- a/src/regexec.c +++ b/src/regexec.c @@ -2373,20 +2373,25 @@ typedef struct { #ifdef ONIG_DEBUG_MATCH #define MATCH_DEBUG_OUT(offset) do {\ - static unsigned int counter = 1;\ UChar *xp, *q, *bp, buf[50];\ - int len;\ + int len, spos;\ + spos = IS_NOT_NULL(s) ? (int )(s - str) : -1;\ xp = p - (offset);\ fprintf(stderr, "%7u: %7ld: %4d> \"",\ - counter, GET_STACK_INDEX(stk), (int )(s - str));\ + counter, GET_STACK_INDEX(stk), spos);\ counter++;\ bp = buf;\ - for (i = 0, q = s; i < 7 && q < end; i++) {\ - len = enclen(encode, q);\ - while (len-- > 0) *bp++ = *q++;\ + if (IS_NOT_NULL(s)) {\ + for (i = 0, q = s; i < 7 && q < end; i++) {\ + len = enclen(encode, q);\ + while (len-- > 0) *bp++ = *q++;\ + }\ + if (q < end) { xmemcpy(bp, "...\"", 4); bp += 4; }\ + else { xmemcpy(bp, "\"", 1); bp += 1; }\ + }\ + else {\ + xmemcpy(bp, "\"", 1); bp += 1;\ }\ - if (q < end) { xmemcpy(bp, "...\"", 4); bp += 4; }\ - else { xmemcpy(bp, "\"", 1); bp += 1; }\ *bp = 0;\ fputs((char* )buf, stderr);\ for (i = 0; i < 20 - (bp - buf); i++) fputc(' ', stderr);\ @@ -2540,6 +2545,10 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, OnigEncoding encode = reg->enc; OnigCaseFoldType case_fold_flag = reg->case_fold_flag; +#ifdef ONIG_DEBUG_MATCH + static unsigned int counter = 1; +#endif + #ifdef USE_CALLOUT msa->mp->match_at_call_counter++; #endif