使用 C 函数 notify_notification_update() 的段错误

Segfault with C function notify_notification_update()

很简单,我在调用 libnotify 函数时遇到了段错误。错误代码:

int lua_libnotify_new(lua_State *L) {
    const char *summary = luaL_checkstring(L, 1);
    const char *body = lua_isstring(L, 2) ? lua_tostring(L, 2) : NULL;
    const char *icon = lua_isstring(L, 3) ? lua_tostring(L, 3) : NULL;
    NotifyNotification *notification = (NotifyNotification *)lua_newuserdata(L, sizeof(NotifyNotification));
    /* Error is the below line */
    notify_notification_update(notification, summary, body, icon);
    return 1;
}

经过一些修改,我意识到它应该是 sizeof(NotifyNotification*)。已解决。