summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2012-10-02 11:56:33 +0200
committerMike Pall <mike>2012-10-02 11:56:33 +0200
commit0d7094f36e62854d882c528efb634210b6c9455d (patch)
tree7ca148dd819501007e04216448eba2df179b3ae5
parentb66ab96a629892ade0e0b68ca50a7e850b7e37ec (diff)
downloadluajit-0d7094f36e62854d882c528efb634210b6c9455d.tar.gz
luajit-0d7094f36e62854d882c528efb634210b6c9455d.tar.bz2
luajit-0d7094f36e62854d882c528efb634210b6c9455d.zip
From Lua 5.2: Return nil for bad position in string.find().
Needs -DLUAJIT_ENABLE_LUA52COMPAT.
-rw-r--r--src/lib_string.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/lib_string.c b/src/lib_string.c
index d894f9f4..9c4cee8b 100644
--- a/src/lib_string.c
+++ b/src/lib_string.c
@@ -487,10 +487,16 @@ static int str_find_aux(lua_State *L, int find)
487 const char *s = luaL_checklstring(L, 1, &l1); 487 const char *s = luaL_checklstring(L, 1, &l1);
488 const char *p = luaL_checklstring(L, 2, &l2); 488 const char *p = luaL_checklstring(L, 2, &l2);
489 ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1; 489 ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1;
490 if (init < 0) 490 if (init < 0) {
491 init = 0; 491 init = 0;
492 else if ((size_t)(init) > l1) 492 } else if ((size_t)(init) > l1) {
493#if LJ_52
494 setnilV(L->top-1);
495 return 1;
496#else
493 init = (ptrdiff_t)l1; 497 init = (ptrdiff_t)l1;
498#endif
499 }
494 if (find && (lua_toboolean(L, 4) || /* explicit request? */ 500 if (find && (lua_toboolean(L, 4) || /* explicit request? */
495 strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */ 501 strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */
496 /* do a plain search */ 502 /* do a plain search */