From c5a2cddab8261e6e568c1384499e08c16cc45ac9 Mon Sep 17 00:00:00 2001 From: "K.Kosako" Date: Sun, 21 Mar 2021 21:08:17 +0900 Subject: [PATCH] escape warnings for VisualStudio 2019 --- src/regexec.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/regexec.c b/src/regexec.c index 5f784fbf..27e66058 100644 --- a/src/regexec.c +++ b/src/regexec.c @@ -54,6 +54,9 @@ (MEM_STATUS_AT((reg)->push_mem_end, (idx)) != 0 ? \ STACK_AT(mem_end_stk[idx].i)->u.mem.pstr : mem_end_stk[idx].s) +#define DIST_CAST(d) (int )(d) + + static int forward_search(regex_t* reg, const UChar* str, const UChar* end, UChar* start, UChar* range, UChar** low, UChar** high); static int @@ -4495,7 +4498,7 @@ regset_search_body_position_lead(OnigRegSet* set, sr[i].state = SRS_DEAD; if (reg->optimize != OPTIMIZE_NONE) { if (reg->dist_max != INFINITE_LEN) { - if (end - range > reg->dist_max) + if (end - range > DIST_CAST(reg->dist_max)) sch_range = (UChar* )range + reg->dist_max; else sch_range = (UChar* )end; @@ -5158,7 +5161,7 @@ forward_search(regex_t* reg, const UChar* str, const UChar* end, UChar* start, p = start; if (reg->dist_min != 0) { - if (end - p <= reg->dist_min) + if (end - p <= DIST_CAST(reg->dist_min)) return 0; /* fail */ if (ONIGENC_IS_SINGLEBYTE(reg->enc)) { @@ -5191,7 +5194,7 @@ forward_search(regex_t* reg, const UChar* str, const UChar* end, UChar* start, } if (p && p < range) { - if (p - start < reg->dist_min) { + if (p - start < DIST_CAST(reg->dist_min)) { retry_gate: pprev = p; p += enclen(reg->enc, p); @@ -5236,7 +5239,7 @@ forward_search(regex_t* reg, const UChar* str, const UChar* end, UChar* start, } else { if (reg->dist_max != INFINITE_LEN) { - if (p - str < reg->dist_max) { + if (p - str < DIST_CAST(reg->dist_max)) { *low = (UChar* )str; } else { @@ -5247,7 +5250,7 @@ forward_search(regex_t* reg, const UChar* str, const UChar* end, UChar* start, } } /* no needs to adjust *high, *high is used as range check only */ - if (p - str < reg->dist_min) + if (p - str < DIST_CAST(reg->dist_min)) *high = (UChar* )str; else *high = p - reg->dist_min; @@ -5332,13 +5335,13 @@ backward_search(regex_t* reg, const UChar* str, const UChar* end, UChar* s, } if (reg->dist_max != INFINITE_LEN) { - if (p - str < reg->dist_max) + if (p - str < DIST_CAST(reg->dist_max)) *low = (UChar* )str; else *low = p - reg->dist_max; if (reg->dist_min != 0) { - if (p - str < reg->dist_min) + if (p - str < DIST_CAST(reg->dist_min)) *high = (UChar* )str; else *high = p - reg->dist_min; @@ -5482,13 +5485,13 @@ search_in_range(regex_t* reg, const UChar* str, const UChar* end, if (range > start) { if (reg->anc_dist_max != INFINITE_LEN && - min_semi_end - start > reg->anc_dist_max) { + min_semi_end - start > DIST_CAST(reg->anc_dist_max)) { start = min_semi_end - reg->anc_dist_max; if (start < end) start = onigenc_get_right_adjust_char_head(reg->enc, str, start); } - if (max_semi_end - (range - 1) < reg->anc_dist_min) { - if (max_semi_end - str + 1 < reg->anc_dist_min) + if (max_semi_end - (range - 1) < DIST_CAST(reg->anc_dist_min)) { + if (max_semi_end - str + 1 < DIST_CAST(reg->anc_dist_min)) goto mismatch_no_msa; else range = max_semi_end - reg->anc_dist_min + 1; @@ -5500,11 +5503,11 @@ search_in_range(regex_t* reg, const UChar* str, const UChar* end, } else { if (reg->anc_dist_max != INFINITE_LEN && - min_semi_end - range > reg->anc_dist_max) { + min_semi_end - range > DIST_CAST(reg->anc_dist_max)) { range = min_semi_end - reg->anc_dist_max; } - if (max_semi_end - start < reg->anc_dist_min) { - if (max_semi_end - str < reg->anc_dist_min) + if (max_semi_end - start < DIST_CAST(reg->anc_dist_min)) { + if (max_semi_end - str < DIST_CAST(reg->anc_dist_min)) goto mismatch_no_msa; else { start = max_semi_end - reg->anc_dist_min; @@ -5575,7 +5578,7 @@ search_in_range(regex_t* reg, const UChar* str, const UChar* end, if (reg->dist_max == INFINITE_LEN) sch_range = (UChar* )end; else { - if ((end - range) < reg->dist_max) + if (end - range < DIST_CAST(reg->dist_max)) sch_range = (UChar* )end; else { sch_range = (UChar* )range + reg->dist_max; @@ -5651,14 +5654,14 @@ search_in_range(regex_t* reg, const UChar* str, const UChar* end, else adjrange = (UChar* )end; - if (end - range > reg->dist_min) + if (end - range > DIST_CAST(reg->dist_min)) min_range = range + reg->dist_min; else min_range = end; if (reg->dist_max != INFINITE_LEN) { do { - if (end - s > reg->dist_max) + if (end - s > DIST_CAST(reg->dist_max)) sch_start = s + reg->dist_max; else { sch_start = onigenc_get_prev_char_head(reg->enc, str, end);