From d4bc6ab756371b744f3e0030d5cf0b24bffdf24c Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Thu, 21 Feb 2013 16:22:26 +0100 Subject: [PATCH] Fix memory access check for fast string interning. --- src/lj_str.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lj_str.c b/src/lj_str.c index e63d8628..6548ee4d 100644 --- a/src/lj_str.c +++ b/src/lj_str.c @@ -48,7 +48,7 @@ static LJ_AINLINE int str_fastcmp(const char *a, const char *b, MSize len) { MSize i = 0; lua_assert(len > 0); - lua_assert((((uintptr_t)a + len) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4); + lua_assert((((uintptr_t)a+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4); do { /* Note: innocuous access up to end of string + 3. */ uint32_t v = lj_getu32(a+i) ^ *(const uint32_t *)(b+i); if (v) { @@ -121,7 +121,7 @@ GCstr *lj_str_new(lua_State *L, const char *str, size_t lenx) h ^= b; h -= lj_rol(b, 16); /* Check if the string has already been interned. */ o = gcref(g->strhash[h & g->strmask]); - if (LJ_LIKELY((((uintptr_t)str + len) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4)) { + if (LJ_LIKELY((((uintptr_t)str+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4)) { while (o != NULL) { GCstr *sx = gco2str(o); if (sx->len == len && str_fastcmp(str, strdata(sx), len) == 0) {