Skip to content

Commit 2b7abf2

Browse files
committed
Fix a Lua stack overflow in the C callback MJLuaCompletionsForWord
1 parent 901b7ab commit 2b7abf2

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Hammerspoon/MJLua.m

+3-6
Original file line numberDiff line numberDiff line change
@@ -787,19 +787,16 @@ void MJLuaDealloc(void) {
787787
_lua_stackguard_entry(skin.L);
788788

789789
[skin pushLuaRef:refTable ref:completionsForWordFn];
790-
if (!lua_isfunction(skin.L, -1)) {
791-
HSNSLOG(@"ERROR: MJLuaCompletionsForWord doesn't seem to have a completionsForWordFn");
792-
_lua_stackguard_exit(skin.L);
793-
return @[];
794-
}
795790
[skin pushNSObject:completionWord];
796791
if ([skin protectedCallAndError:@"MJLuaCompletionsForWord" nargs:1 nresults:1] == NO) {
797792
_lua_stackguard_exit(skin.L);
798793
return @[];
799794
}
800795

796+
NSArray *completions = [skin toNSObjectAtIndex:-1];
797+
lua_pop(skin.L, 1);
801798
_lua_stackguard_exit(skin.L);
802-
return [skin toNSObjectAtIndex:-1];
799+
return completions;
803800
}
804801

805802
// C-Code helper to return current active LuaState. Useful for callbacks to

0 commit comments

Comments
 (0)