Mes recomanacions de cppcheck aplicades
Abans de tocar unes cosetes de strings buits
This commit is contained in:
@@ -50,25 +50,25 @@ void ManageHiScoreTable::sort()
|
||||
{
|
||||
struct
|
||||
{
|
||||
bool operator()(HiScoreEntry a, HiScoreEntry b) const { return a.score > b.score; }
|
||||
bool operator()(HiScoreEntry &a, HiScoreEntry &b) const { return a.score > b.score; }
|
||||
} custom_less;
|
||||
|
||||
std::sort(table_->begin(), table_->end(), custom_less);
|
||||
}
|
||||
|
||||
// Carga la tabla con los datos de un fichero
|
||||
bool ManageHiScoreTable::loadFromFile(std::string file_path)
|
||||
bool ManageHiScoreTable::loadFromFile(const std::string &file_path)
|
||||
{
|
||||
clear();
|
||||
|
||||
auto success = true;
|
||||
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
auto file = SDL_RWFromFile(file_path.c_str(), "r+b");
|
||||
|
||||
if (file)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Reading file: " << filename.c_str() << std::endl;
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
std::cout << "Reading file: " << file_name.c_str() << std::endl;
|
||||
#endif
|
||||
for (int i = 0; i < (int)table_->size(); ++i)
|
||||
{
|
||||
@@ -86,7 +86,7 @@ bool ManageHiScoreTable::loadFromFile(std::string file_path)
|
||||
break;
|
||||
}
|
||||
|
||||
char *name = (char *)malloc(nameSize + 1);
|
||||
char *name = static_cast<char *>(malloc(nameSize + 1));
|
||||
if (SDL_RWread(file, name, sizeof(char) * nameSize, 1) == 0)
|
||||
{
|
||||
success = false;
|
||||
@@ -113,10 +113,12 @@ bool ManageHiScoreTable::loadFromFile(std::string file_path)
|
||||
}
|
||||
|
||||
// Guarda la tabla en un fichero
|
||||
bool ManageHiScoreTable::saveToFile(std::string file_path)
|
||||
bool ManageHiScoreTable::saveToFile(const std::string &file_path)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
#endif
|
||||
auto success = true;
|
||||
const std::string fileName = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
auto file = SDL_RWFromFile(file_path.c_str(), "w+b");
|
||||
|
||||
if (file)
|
||||
@@ -131,7 +133,7 @@ bool ManageHiScoreTable::saveToFile(std::string file_path)
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Writing file: " << fileName.c_str() << std::endl;
|
||||
std::cout << "Writing file: " << file_name.c_str() << std::endl;
|
||||
#endif
|
||||
// Cierra el fichero
|
||||
SDL_RWclose(file);
|
||||
@@ -139,7 +141,7 @@ bool ManageHiScoreTable::saveToFile(std::string file_path)
|
||||
else
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Error: Unable to save " << fileName.c_str() << " file! " << SDL_GetError() << std::endl;
|
||||
std::cout << "Error: Unable to save " << file_name.c_str() << " file! " << SDL_GetError() << std::endl;
|
||||
#endif
|
||||
}
|
||||
return success;
|
||||
|
||||
Reference in New Issue
Block a user