From c2f148e15d96e0d65879cb5c07f98c8b8eebbdef Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 10 Jan 2024 16:21:39 +0900 Subject: [PATCH] string.c (mrb_memsearch_qs): reduce the scope of local variables --- src/string.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/string.c b/src/string.c index c6f419247..a972caba6 100644 --- a/src/string.c +++ b/src/string.c @@ -477,15 +477,17 @@ mrb_memsearch_qs(const unsigned char *xs, mrb_int m, const unsigned char *ys, mr return -1; } else { - const unsigned char *x = xs, *xe = xs + m; const unsigned char *y = ys; ptrdiff_t qstable[256]; /* Preprocessing */ for (int i = 0; i < 256; i++) qstable[i] = m + 1; + + const unsigned char *x = xs, *xe = xs + m; for (; x < xe; x++) qstable[*x] = xe - x; + /* Searching */ for (; y + m <= ys + n; y += *(qstable + y[m])) { if (*xs == *y && memcmp(xs, y, m) == 0)