Fix invalid usage of temporary object in mainmenu json conversion
authorsapier <Sapier at GMX dot net>
Sat, 9 Nov 2013 21:51:12 +0000 (22:51 +0100)
committersapier <Sapier at GMX dot net>
Mon, 11 Nov 2013 22:23:58 +0000 (23:23 +0100)
src/script/lua_api/l_mainmenu.cpp

index ff0d5277414b4b5090fc464cea3b4239369e2bfb..498ac038394eb6920fa221d4c7472296d8eec2f8 100644 (file)
@@ -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);
                }