[Super-tux-commit] supertux/lib/utils configfile.cpp,1.6,1.7 configfile.h,1.4,1.5
Brought to you by:
wkendrick
From: Tobias G. <to...@us...> - 2004-08-06 11:43:26
|
Update of /cvsroot/super-tux/supertux/lib/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10574/lib/utils Modified Files: configfile.cpp configfile.h Log Message: Converted many char*s to std::strings. This is providing more safety from buffer overflows and anyway more straightforward string handling. Index: configfile.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/utils/configfile.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- configfile.h 25 Jul 2004 19:03:35 -0000 1.4 +++ configfile.h 6 Aug 2004 11:43:08 -0000 1.5 @@ -24,7 +24,7 @@ namespace SuperTux { -FILE * opendata(const char * filename, const char * mode); +FILE * opendata(const std::string& filename, const char * mode); class Config { public: Index: configfile.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/utils/configfile.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- configfile.cpp 27 Jul 2004 19:31:38 -0000 1.6 +++ configfile.cpp 6 Aug 2004 11:43:08 -0000 1.7 @@ -49,32 +49,25 @@ SoundManager::get()->enable_music(true); } -FILE * SuperTux::opendata(const char * rel_filename, const char * mode) +FILE * SuperTux::opendata(const std::string& rel_filename, const char *mode) { - char * filename = NULL; + std::string filename; FILE * fi; - filename = (char *) malloc(sizeof(char) * (strlen(st_dir) + - strlen(rel_filename) + 1)); - - strcpy(filename, st_dir); - /* Open the high score file: */ - - strcat(filename, rel_filename); + filename = st_dir + rel_filename; /* Try opening the file: */ - fi = fopen(filename, mode); + fi = fopen(filename.c_str(), mode); if (fi == NULL) { - fprintf(stderr, "Warning: Unable to open the file \"%s\" ", filename); + fprintf(stderr, "Warning: Unable to open the file \"%s\" ", filename.c_str()); if (strcmp(mode, "r") == 0) fprintf(stderr, "for read!!!\n"); else if (strcmp(mode, "w") == 0) fprintf(stderr, "for write!!!\n"); } - free( filename ); return(fi); } |