[Super-tux-commit] supertux/src gameloop.cpp,1.164,1.165 level_subset.cpp,1.9,1.10 leveleditor.cpp,1
Brought to you by:
wkendrick
From: Tobias G. <to...@us...> - 2004-08-06 11:43:27
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10574/src Modified Files: gameloop.cpp level_subset.cpp leveleditor.cpp title.cpp Log Message: Converted many char*s to std::strings. This is providing more safety from buffer overflows and anyway more straightforward string handling. Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.164 retrieving revision 1.165 diff -u -d -r1.164 -r1.165 --- gameloop.cpp 28 Jul 2004 23:06:12 -0000 1.164 +++ gameloop.cpp 6 Aug 2004 11:43:09 -0000 1.165 @@ -20,6 +20,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <iostream> +#include <sstream> #include <cassert> #include <cstdio> #include <cstdlib> @@ -799,12 +800,14 @@ std::string slotinfo(int slot) { - char tmp[1024]; - char slotfile[1024]; + std::string tmp; + std::string slotfile; std::string title; - sprintf(slotfile,"%s/slot%d.stsg",st_save_dir,slot); + std::stringstream stream; + stream << slot; + slotfile = st_save_dir + "/slot" + stream.str() + ".stsg"; - lisp_object_t* savegame = lisp_read_from_file(slotfile); + lisp_object_t* savegame = lisp_read_from_file(slotfile.c_str()); if (savegame) { LispReader reader(lisp_cdr(savegame)); @@ -812,15 +815,15 @@ lisp_free(savegame); } - if (access(slotfile, F_OK) == 0) + if (access(slotfile.c_str(), F_OK) == 0) { if (!title.empty()) - snprintf(tmp,1024,"Slot %d - %s",slot, title.c_str()); + tmp = "Slot " + stream.str() + " - " + title; else - snprintf(tmp, 1024,_("Slot %d - Savegame"),slot); + tmp = "Slot " + stream.str() + " - Savegame"; } else - sprintf(tmp,_("Slot %d - Free"),slot); + tmp = std::string(_("Slot")) + " " + stream.str() + " - " + std::string(_("Free")); return tmp; } @@ -831,10 +834,11 @@ if(slot != -1 && load_game_menu->get_item_by_id(slot).kind == MN_ACTION) { - char slotfile[1024]; - snprintf(slotfile, 1024, "%s/slot%d.stsg", st_save_dir, slot); + std::stringstream stream; + stream << slot; + std::string slotfile = st_save_dir + "/slot" + stream.str() + ".stsg"; - if (access(slotfile, F_OK) != 0) + if (access(slotfile.c_str(), F_OK) != 0) { draw_intro(); } Index: title.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.cpp,v retrieving revision 1.115 retrieving revision 1.116 diff -u -d -r1.115 -r1.116 --- title.cpp 29 Jul 2004 11:05:28 -0000 1.115 +++ title.cpp 6 Aug 2004 11:43:10 -0000 1.116 @@ -20,6 +20,7 @@ // 02111-1307, USA. #include <iostream> +#include <sstream> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -279,7 +280,7 @@ img_choose_subset = new Surface(datadir + "/images/status/choose-level-subset.png", true); /* Generating contrib maps by only using a string_list */ - worldmap_list = FileSystem::dfiles("levels/worldmap", NULL, "icyisland.stwm"); + worldmap_list = FileSystem::dfiles("levels/worldmap", "", "icyisland.stwm"); titlesession->get_current_sector()->activate(); titlesession->set_current(); @@ -379,14 +380,15 @@ if(event.key.keysym.sym == SDLK_DELETE) { int slot = menu->get_active_item_id(); - char str[1024]; - sprintf(str,_("Are you sure you want to delete slot %d?"), slot); + std::stringstream stream; + stream << slot; + std::string str = _("Are you sure you want to delete slot") + stream.str() + "?"; - if(confirm_dialog(bkg_title, str)) + if(confirm_dialog(bkg_title, str.c_str())) { - sprintf(str,"%s/slot%d.stsg", st_save_dir, slot); - printf("Removing: %s\n",str); - remove(str); + str = st_save_dir + "/slot" + stream.str() + ".stsg"; + printf("Removing: %s\n",str.c_str()); + remove(str.c_str()); } update_load_save_game_menu(load_game_menu); Index: level_subset.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level_subset.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- level_subset.cpp 28 Jul 2004 23:47:54 -0000 1.9 +++ level_subset.cpp 6 Aug 2004 11:43:09 -0000 1.10 @@ -82,16 +82,16 @@ // Check in which directory our subset is located (ie. ~/.supertux/ // or SUPERTUX_DATADIR) - char filename[1024]; - snprintf(filename, 1024, "%s/levels/%s/", st_dir, subset); - if (access(filename, R_OK) == 0) + std::string filename; + filename = st_dir + "/levels/" + subset + "/"; + if (access(filename.c_str(), R_OK) == 0) { directory = filename; } else { - snprintf(filename, 1024, "%s/levels/%s/", datadir.c_str(), subset); - if (access(filename, R_OK) == 0) + filename = datadir + "/levels/" + subset + "/"; + if (access(filename.c_str(), R_OK) == 0) directory = filename; else std::cout << "Error: LevelSubset: couldn't find subset: " << subset << std::endl; @@ -104,14 +104,14 @@ // directory to see what we can find std::set<std::string> files; - snprintf(filename, 1024, "%s/levels/%s/", st_dir, subset); - if(access(filename, R_OK) == 0) + filename = st_dir + "/levels/" + subset + "/"; + if(access(filename.c_str(), R_OK) == 0) { files = FileSystem::read_directory(filename); } else { - snprintf(filename, 1024, "%s/levels/%s/", datadir.c_str(), subset); + filename = datadir + "/levels/" + subset + "/"; files = FileSystem::read_directory(filename); } Index: leveleditor.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/leveleditor.cpp,v retrieving revision 1.147 retrieving revision 1.148 diff -u -d -r1.147 -r1.148 --- leveleditor.cpp 5 Aug 2004 18:58:08 -0000 1.147 +++ leveleditor.cpp 6 Aug 2004 11:43:09 -0000 1.148 @@ -544,8 +544,8 @@ level_settings_menu->get_item_by_id(MNID_NAME).change_input(le_level->name.c_str()); level_settings_menu->get_item_by_id(MNID_AUTHOR).change_input(le_level->author.c_str()); - level_settings_menu->get_item_by_id(MNID_SONG).list.first = FileSystem::dfiles("music/",NULL, "-fast"); - level_settings_menu->get_item_by_id(MNID_BGIMG).list.first = FileSystem::dfiles("images/background",NULL, NULL); + level_settings_menu->get_item_by_id(MNID_SONG).list.first = FileSystem::dfiles("music/","", "-fast"); + level_settings_menu->get_item_by_id(MNID_BGIMG).list.first = FileSystem::dfiles("images/background","", ""); level_settings_menu->get_item_by_id(MNID_BGIMG).list.first.insert(""); level_settings_menu->get_item_by_id(MNID_PARTICLE).list.first.insert(""); level_settings_menu->get_item_by_id(MNID_PARTICLE).list.first.insert("snow"); |