mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* re.c (rb_memsearch): fix overrun. [ruby-talk:80759]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4477 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
26fcfd1bb5
commit
157c60a09f
2 changed files with 17 additions and 10 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Tue Sep 2 00:44:37 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* re.c (rb_memsearch): fix overrun. [ruby-talk:80759]
|
||||||
|
|
||||||
Tue Sep 2 00:41:27 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue Sep 2 00:41:27 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* ext/iconv/iconv.c (map_charset): use lower case keys.
|
* ext/iconv/iconv.c (map_charset): use lower case keys.
|
||||||
|
|
23
re.c
23
re.c
|
@ -107,7 +107,8 @@ rb_memsearch(x0, m, y0, n)
|
||||||
|
|
||||||
#define KR_REHASH(a, b, h) (((h) << 1) - ((a)<<d) + (b))
|
#define KR_REHASH(a, b, h) (((h) << 1) - ((a)<<d) + (b))
|
||||||
|
|
||||||
s = y; e = s + n - m + 1;
|
if (m > n) return -1;
|
||||||
|
s = y; e = s + n - m;
|
||||||
|
|
||||||
/* Preprocessing */
|
/* Preprocessing */
|
||||||
/* computes d = 2^(m-1) with
|
/* computes d = 2^(m-1) with
|
||||||
|
@ -116,36 +117,38 @@ rb_memsearch(x0, m, y0, n)
|
||||||
if (d > m) d = m;
|
if (d > m) d = m;
|
||||||
|
|
||||||
if (ruby_ignorecase) {
|
if (ruby_ignorecase) {
|
||||||
|
if (n == m) {
|
||||||
|
return rb_memcicmp(x, s, m) == 0 ? 0 : -1;
|
||||||
|
}
|
||||||
/* Prepare hash value */
|
/* Prepare hash value */
|
||||||
for (hy = hx = i = 0; i < d; ++i) {
|
for (hy = hx = i = 0; i < d; ++i) {
|
||||||
hx = KR_REHASH(0, casetable[x[i]], hx);
|
hx = KR_REHASH(0, casetable[x[i]], hx);
|
||||||
hy = KR_REHASH(0, casetable[s[i]], hy);
|
hy = KR_REHASH(0, casetable[s[i]], hy);
|
||||||
}
|
}
|
||||||
/* Searching */
|
/* Searching */
|
||||||
while (s < e) {
|
while (hx != hy || rb_memcicmp(x, s, m)) {
|
||||||
if (hx == hy && rb_memcicmp(x, s, m) == 0) {
|
if (s >= e) return -1;
|
||||||
return s-y;
|
|
||||||
}
|
|
||||||
hy = KR_REHASH(casetable[*s], casetable[*(s+d)], hy);
|
hy = KR_REHASH(casetable[*s], casetable[*(s+d)], hy);
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (n == m) {
|
||||||
|
return memcmp(x, s, m) == 0 ? 0 : -1;
|
||||||
|
}
|
||||||
/* Prepare hash value */
|
/* Prepare hash value */
|
||||||
for (hy = hx = i = 0; i < d; ++i) {
|
for (hy = hx = i = 0; i < d; ++i) {
|
||||||
hx = KR_REHASH(0, x[i], hx);
|
hx = KR_REHASH(0, x[i], hx);
|
||||||
hy = KR_REHASH(0, s[i], hy);
|
hy = KR_REHASH(0, s[i], hy);
|
||||||
}
|
}
|
||||||
/* Searching */
|
/* Searching */
|
||||||
while (s < e) {
|
while (hx != hy || memcmp(x, s, m)) {
|
||||||
if (hx == hy && memcmp(x, s, m) == 0) {
|
if (s >= e) return -1;
|
||||||
return s-y;
|
|
||||||
}
|
|
||||||
hy = KR_REHASH(*s, *(s+d), hy);
|
hy = KR_REHASH(*s, *(s+d), hy);
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return s-y;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define REG_CASESTATE FL_USER0
|
#define REG_CASESTATE FL_USER0
|
||||||
|
|
Loading…
Reference in a new issue