mkottman/lqt — Issue #17: QMenu::actionAt() and similar methods can return boxed NULL pointers
Author: ToxicFrog
Created: 2012-01-22 17:00:13+00:00
State: open

Any method that returns "a QSomething* or NULL" - such as QMenu::actionAt() or QGraphicsScene::itemAt() - will, in the latter case, return a boxed NULL pointer rather than nil.

Reproduction:

require "qtcore"
require "qtgui"

local app = QApplication(1, arg)
local menu = QMenu("test")
local action = menu:actionAt(QPoint(0,0))

print(action) -- we haven't added any actions, so actionAt() should return NULL
print(action.__type)
print(action:menu()) -- follows the null pointer into oblivion

This is expected to output "nil" and then raise a nil-value-index error; instead it outputs "userdata", "QAction*", and then raises an "instance already deleted" error.

Simple fix:

```
--- a/common/lqt_common.cpp
+++ b/common/lqt_common.cpp
@@ -438,6 +438,12 @@ void lqtL_unregister (lua_State *L, const void *p) {

void lqtL_pushudata (lua_State *L, const void *p, const char *name) {
bool already = false;
+
+ if (p == NULL) {
+ lua_pushnil(L); // (1)
+ return;
+ }
+
lqtL_ensurepointer(L, p); // (1)
if (lua_getmetatable(L, -1)) {
// (2)
```