Skip to content

Commit

Permalink
Fix invalid usage of temporary object in mainmenu json conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
sapier authored and sapier committed Nov 11, 2013
1 parent bb54e2c commit a935d81
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/script/lua_api/l_mainmenu.cpp
Expand Up @@ -453,12 +453,11 @@ int ModApiMainMenu::l_get_favorites(lua_State *L)
int top_lvl2 = lua_gettop(L);

if (servers[i]["clients"].asString().size()) {

const char* clients_raw = servers[i]["clients"].asString().c_str();
std::string clients_raw = servers[i]["clients"].asString();
char* endptr = 0;
int numbervalue = strtol(clients_raw,&endptr,10);
int numbervalue = strtol(clients_raw.c_str(),&endptr,10);

if ((*clients_raw != 0) && (*endptr == 0)) {
if ((clients_raw != "") && (*endptr == 0)) {
lua_pushstring(L,"clients");
lua_pushnumber(L,numbervalue);
lua_settable(L, top_lvl2);
Expand All @@ -467,11 +466,11 @@ int ModApiMainMenu::l_get_favorites(lua_State *L)

if (servers[i]["clients_max"].asString().size()) {

const char* clients_max_raw = servers[i]["clients_max"].asString().c_str();
std::string clients_max_raw = servers[i]["clients_max"].asString();
char* endptr = 0;
int numbervalue = strtol(clients_max_raw,&endptr,10);
int numbervalue = strtol(clients_max_raw.c_str(),&endptr,10);

if ((*clients_max_raw != 0) && (*endptr == 0)) {
if ((clients_max_raw != "") && (*endptr == 0)) {
lua_pushstring(L,"clients_max");
lua_pushnumber(L,numbervalue);
lua_settable(L, top_lvl2);
Expand All @@ -480,7 +479,8 @@ int ModApiMainMenu::l_get_favorites(lua_State *L)

if (servers[i]["version"].asString().size()) {
lua_pushstring(L,"version");
lua_pushstring(L,servers[i]["version"].asString().c_str());
std::string topush = servers[i]["version"].asString();
lua_pushstring(L,topush.c_str());
lua_settable(L, top_lvl2);
}

Expand Down Expand Up @@ -510,25 +510,29 @@ int ModApiMainMenu::l_get_favorites(lua_State *L)

if (servers[i]["description"].asString().size()) {
lua_pushstring(L,"description");
lua_pushstring(L,servers[i]["description"].asString().c_str());
std::string topush = servers[i]["description"].asString();
lua_pushstring(L,topush.c_str());
lua_settable(L, top_lvl2);
}

if (servers[i]["name"].asString().size()) {
lua_pushstring(L,"name");
lua_pushstring(L,servers[i]["name"].asString().c_str());
std::string topush = servers[i]["name"].asString();
lua_pushstring(L,topush.c_str());
lua_settable(L, top_lvl2);
}

if (servers[i]["address"].asString().size()) {
lua_pushstring(L,"address");
lua_pushstring(L,servers[i]["address"].asString().c_str());
std::string topush = servers[i]["address"].asString();
lua_pushstring(L,topush.c_str());
lua_settable(L, top_lvl2);
}

if (servers[i]["port"].asString().size()) {
lua_pushstring(L,"port");
lua_pushstring(L,servers[i]["port"].asString().c_str());
std::string topush = servers[i]["port"].asString();
lua_pushstring(L,topush.c_str());
lua_settable(L, top_lvl2);
}

Expand Down

0 comments on commit a935d81

Please sign in to comment.