使用C函数notify_notification_update()出现Segmentation fault错误。

简单说,我在调用 libnotify 函数时遇到了 segfault 错误。出错的代码:

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));
    /* 错误出现在下面这行代码 */
    notify_notification_update(notification, summary, body, icon);
    return 1;
}
点赞
用户3188999
用户3188999

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

2015-11-06 20:09:02