check if string msg is not NULL, fix segfault

This commit is contained in:
Jacek Jendrzej
2016-05-19 15:22:15 +02:00
parent e7e158a273
commit c9e8a57418
4 changed files with 37 additions and 17 deletions

View File

@@ -56,8 +56,10 @@ bool CLuaMenuChangeObserver::changeNotify(lua_State *L, const std::string &luaAc
lua_pushstring(L, optionValue);
int status = lua_pcall(L, 2 /* two args */, 1 /* one result */, 0);
if (status) {
fprintf(stderr, "[CLuaMenuChangeObserver::%s:%d] error in script: %s\n", __func__, __LINE__, lua_tostring(L, -1));
DisplayErrorMessage(lua_tostring(L, -1), "Lua Script Error:");
bool isString = lua_isstring(L,-1);
const char *null = "NULL";
fprintf(stderr, "[CLuaMenuChangeObserver::%s:%d] error in script: %s\n", __func__, __LINE__, isString ? lua_tostring(L, -1): null);
DisplayErrorMessage(isString ? lua_tostring(L, -1):null, "Lua Script Error:");
}
double res = lua_isnumber(L, -1) ? lua_tonumber(L, -1) : 0;
return (((int)res == menu_return::RETURN_REPAINT) || ((int)res == menu_return::RETURN_EXIT_REPAINT));
@@ -135,8 +137,10 @@ int CLuaMenuForwarder::exec(CMenuTarget* /*parent*/, const std::string & /*actio
lua_pushstring(L, luaId.c_str());
int status = lua_pcall(L, 1 /* one arg */, 1 /* one result */, 0);
if (status) {
fprintf(stderr, "[CLuaMenuForwarder::%s:%d] error in script: %s\n", __func__, __LINE__, lua_tostring(L, -1));
DisplayErrorMessage(lua_tostring(L, -1), "Lua Script Error:");
bool isString = lua_isstring(L,-1);
const char *null = "NULL";
fprintf(stderr, "[CLuaMenuForwarder::%s:%d] error in script: %s\n", __func__, __LINE__, isString ? lua_tostring(L, -1):null);
DisplayErrorMessage(isString ? lua_tostring(L, -1):null, "Lua Script Error:");
}
if (lua_isnumber(L, -1))
res = (int) lua_tonumber(L, -1);
@@ -179,8 +183,10 @@ int CLuaMenuFilebrowser::exec(CMenuTarget* /*parent*/, const std::string& /*acti
lua_pushstring(L, value->c_str());
int status = lua_pcall(L, 2 /* two arg */, 1 /* one result */, 0);
if (status) {
fprintf(stderr, "[CLuaMenuFilebrowser::%s:%d] error in script: %s\n", __func__, __LINE__, lua_tostring(L, -1));
DisplayErrorMessage(lua_tostring(L, -1), "Lua Script Error:");
bool isString = lua_isstring(L,-1);
const char *null = "NULL";
fprintf(stderr, "[CLuaMenuFilebrowser::%s:%d] error in script: %s\n", __func__, __LINE__, isString ? lua_tostring(L, -1):null);
DisplayErrorMessage(isString ? lua_tostring(L, -1):null, "Lua Script Error:");
}
lua_pop(L, 1);
}
@@ -222,8 +228,10 @@ int CLuaMenuStringinput::exec(CMenuTarget* /*parent*/, const std::string & /*act
lua_pushstring(L, value->c_str());
int status = lua_pcall(L, 2 /* two arg */, 1 /* one result */, 0);
if (status) {
fprintf(stderr, "[CLuaMenuStringinput::%s:%d] error in script: %s\n", __func__, __LINE__, lua_tostring(L, -1));
DisplayErrorMessage(lua_tostring(L, -1), "Lua Script Error:");
bool isString = lua_isstring(L,-1);
const char *null = "NULL";
fprintf(stderr, "[CLuaMenuStringinput::%s:%d] error in script: %s\n", __func__, __LINE__, isString ? lua_tostring(L, -1):null);
DisplayErrorMessage(isString ? lua_tostring(L, -1):null, "Lua Script Error:");
}
lua_pop(L, 2);
}
@@ -260,8 +268,10 @@ int CLuaMenuKeyboardinput::exec(CMenuTarget* /*parent*/, const std::string & /*a
lua_pushstring(L, value->c_str());
int status = lua_pcall(L, 2 /* two arg */, 1 /* one result */, 0);
if (status) {
fprintf(stderr, "[CLuaMenuKeyboardinput::%s:%d] error in script: %s\n", __func__, __LINE__, lua_tostring(L, -1));
DisplayErrorMessage(lua_tostring(L, -1), "Lua Script Error:");
bool isString = lua_isstring(L,-1);
const char *null = "NULL";
fprintf(stderr, "[CLuaMenuKeyboardinput::%s:%d] error in script: %s\n", __func__, __LINE__, isString ? lua_tostring(L, -1):null);
DisplayErrorMessage(isString ? lua_tostring(L, -1):null, "Lua Script Error:");
}
lua_pop(L, 2);
}