diff --git a/lua.c b/lua.c index c532e52..25bb2dc 100755 --- a/lua.c +++ b/lua.c @@ -321,8 +321,11 @@ zval *php_lua_get_zval_from_lua(lua_State *L, int index, zval *lua_obj, zval *rv break; case LUA_TTABLE: array_init(rv); + lua_pushvalue(L, index); /* stack now contains: -1 => table */ + lua_pushnil(L); /* first key */ - while (lua_next(L, index-1) != 0) { + /* stack now contains: -1 => nil; -2 => table */ + while (lua_next(L, -2) != 0) { zval key, val; /* uses 'key' (at index -2) and 'value' (at index -1) */ diff --git a/tests/issue040.phpt b/tests/issue040.phpt new file mode 100644 index 0000000..69965b1 --- /dev/null +++ b/tests/issue040.phpt @@ -0,0 +1,19 @@ +--TEST-- +ISSUE #040 (segment fault) +--SKIPIF-- + +--FILE-- +eval(<< +--EXPECT-- +Array + ( + ) \ No newline at end of file