diff --git a/mquickjs.c b/mquickjs.c index 6fe14f1..8311de9 100644 --- a/mquickjs.c +++ b/mquickjs.c @@ -1473,7 +1473,11 @@ static uint32_t js_string_convert_pos(JSContext *ctx, JSValue val, uint32_t pos, for(ce_idx = 0; ce_idx < JS_STRING_POS_CACHE_SIZE; ce_idx++) { ce1 = &ctx->string_pos_cache[ce_idx]; if (ce1->str == val) { - d = abs(ce1->str_pos[pos_type] - pos); + if (ce1->str_pos[pos_type] > pos) { + d = ce1->str_pos[pos_type] - pos; + } else { + d = pos - ce1->str_pos[pos_type]; + } if (d < d_min) { d_min = d; ce = ce1;