Skip to content

Commit a935d81

Browse files
sapiersapier
sapier
authored and
sapier
committedNov 11, 2013
Fix invalid usage of temporary object in mainmenu json conversion
1 parent bb54e2c commit a935d81

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed
 

‎src/script/lua_api/l_mainmenu.cpp

+16-12
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,11 @@ int ModApiMainMenu::l_get_favorites(lua_State *L)
453453
int top_lvl2 = lua_gettop(L);
454454

455455
if (servers[i]["clients"].asString().size()) {
456-
457-
const char* clients_raw = servers[i]["clients"].asString().c_str();
456+
std::string clients_raw = servers[i]["clients"].asString();
458457
char* endptr = 0;
459-
int numbervalue = strtol(clients_raw,&endptr,10);
458+
int numbervalue = strtol(clients_raw.c_str(),&endptr,10);
460459

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

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

470-
const char* clients_max_raw = servers[i]["clients_max"].asString().c_str();
469+
std::string clients_max_raw = servers[i]["clients_max"].asString();
471470
char* endptr = 0;
472-
int numbervalue = strtol(clients_max_raw,&endptr,10);
471+
int numbervalue = strtol(clients_max_raw.c_str(),&endptr,10);
473472

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

481480
if (servers[i]["version"].asString().size()) {
482481
lua_pushstring(L,"version");
483-
lua_pushstring(L,servers[i]["version"].asString().c_str());
482+
std::string topush = servers[i]["version"].asString();
483+
lua_pushstring(L,topush.c_str());
484484
lua_settable(L, top_lvl2);
485485
}
486486

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

511511
if (servers[i]["description"].asString().size()) {
512512
lua_pushstring(L,"description");
513-
lua_pushstring(L,servers[i]["description"].asString().c_str());
513+
std::string topush = servers[i]["description"].asString();
514+
lua_pushstring(L,topush.c_str());
514515
lua_settable(L, top_lvl2);
515516
}
516517

517518
if (servers[i]["name"].asString().size()) {
518519
lua_pushstring(L,"name");
519-
lua_pushstring(L,servers[i]["name"].asString().c_str());
520+
std::string topush = servers[i]["name"].asString();
521+
lua_pushstring(L,topush.c_str());
520522
lua_settable(L, top_lvl2);
521523
}
522524

523525
if (servers[i]["address"].asString().size()) {
524526
lua_pushstring(L,"address");
525-
lua_pushstring(L,servers[i]["address"].asString().c_str());
527+
std::string topush = servers[i]["address"].asString();
528+
lua_pushstring(L,topush.c_str());
526529
lua_settable(L, top_lvl2);
527530
}
528531

529532
if (servers[i]["port"].asString().size()) {
530533
lua_pushstring(L,"port");
531-
lua_pushstring(L,servers[i]["port"].asString().c_str());
534+
std::string topush = servers[i]["port"].asString();
535+
lua_pushstring(L,topush.c_str());
532536
lua_settable(L, top_lvl2);
533537
}
534538

0 commit comments

Comments
 (0)
Please sign in to comment.