diff options
author | sapier <Sapier at GMX dot net> | 2013-11-09 22:51:12 +0100 |
---|---|---|
committer | sapier <Sapier at GMX dot net> | 2013-11-11 23:23:58 +0100 |
commit | a935d810537853eaeda702b7dc341df1e9de1fd1 (patch) | |
tree | cb891d1164d176356280dbcc9085e77d2f823f88 /src | |
parent | bb54e2cf1d91381e46ba24654a39cc9c1cbadb23 (diff) | |
download | minetest-a935d810537853eaeda702b7dc341df1e9de1fd1.tar.gz minetest-a935d810537853eaeda702b7dc341df1e9de1fd1.tar.bz2 minetest-a935d810537853eaeda702b7dc341df1e9de1fd1.zip |
Fix invalid usage of temporary object in mainmenu json conversion
Diffstat (limited to 'src')
-rw-r--r-- | src/script/lua_api/l_mainmenu.cpp | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index ff0d52774..498ac0383 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -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); @@ -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); @@ -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); } @@ -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); } |