Merge pull request #25 from KroArtem/master

more coverity fixes, get rid of printf in device_manager.cpp
This commit is contained in:
auriamg 2014-02-01 15:20:43 -08:00
commit aa324f31e6
4 changed files with 24 additions and 24 deletions

View File

@ -24,11 +24,13 @@
#include "config/player.hpp"
#include "config/user_config.hpp"
#include "graphics/irr_driver.hpp"
#include "input/wiimote_manager.hpp"
#include "io/file_manager.hpp"
#include "states_screens/kart_selection.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/log.hpp"
#include "utils/translation.hpp"
#include "input/wiimote_manager.hpp"
#define INPUT_MODE_DEBUG 0
@ -56,18 +58,18 @@ bool DeviceManager::initialize()
if(UserConfigParams::logMisc())
{
printf("Initializing Device Manager\n");
printf("---------------------------\n");
Log::info("Device manager","Initializing Device Manager");
Log::info("-","---------------------------");
}
deserialize();
// Assign a configuration to the keyboard, or create one if we haven't yet
if(UserConfigParams::logMisc()) printf("Initializing keyboard support.\n");
if(UserConfigParams::logMisc()) Log::info("Device manager","Initializing keyboard support.");
if (m_keyboard_configs.size() == 0)
{
if(UserConfigParams::logMisc())
printf("No keyboard configuration exists, creating one.\n");
Log::info("Device manager","No keyboard configuration exists, creating one.");
m_keyboard_configs.push_back(new KeyboardConfig());
created = true;
}
@ -79,13 +81,13 @@ bool DeviceManager::initialize()
}
if(UserConfigParams::logMisc())
printf("Initializing gamepad support.\n");
Log::info("Device manager","Initializing gamepad support.");
irr_driver->getDevice()->activateJoysticks(m_irrlicht_gamepads);
int num_gamepads = m_irrlicht_gamepads.size();
if(UserConfigParams::logMisc())
{
printf("Irrlicht reports %d gamepads are attached to the system.\n",
Log::info("Device manager","Irrlicht reports %d gamepads are attached to the system.",
num_gamepads);
}
@ -109,19 +111,19 @@ bool DeviceManager::initialize()
if (UserConfigParams::logMisc())
{
printf("#%d: %s detected...", id, name.c_str());
Log::info("Device manager","#%d: %s detected...", id, name.c_str());
}
// Returns true if new configuration was created
if (getConfigForGamepad(id, name, &gamepadConfig) == true)
{
if(UserConfigParams::logMisc())
printf("creating new configuration.\n");
Log::info("Device manager","creating new configuration.");
created = true;
}
else
{
if(UserConfigParams::logMisc())
printf("using existing configuration.\n");
Log::info("Device manager","using existing configuration.");
}
gamepadConfig->setPlugged();
@ -440,12 +442,12 @@ bool DeviceManager::deserialize()
static std::string filepath = file_manager->getUserConfigFile(INPUT_FILE_NAME);
if(UserConfigParams::logMisc())
printf("Deserializing input.xml...\n");
Log::info("Device manager","Deserializing input.xml...");
if(!file_manager->fileExists(filepath))
{
if(UserConfigParams::logMisc())
printf("Warning: no configuration file exists.\n");
Log::warn("Device manager","No configuration file exists.");
}
else
{
@ -499,15 +501,15 @@ bool DeviceManager::deserialize()
{
if(keyboard_config != NULL)
if(!keyboard_config->deserializeAction(xml))
std::cerr << "Ignoring an ill-formed keyboard action in input config.\n";
Log::error("Device manager","Ignoring an ill-formed keyboard action in input config.");
}
else if(reading_now == GAMEPAD)
{
if(gamepad_config != NULL)
if(!gamepad_config->deserializeAction(xml))
std::cerr << "Ignoring an ill-formed gamepad action in input config.\n";
Log::error("Device manager","Ignoring an ill-formed gamepad action in input config.");
}
else std::cerr << "Warning: An action is placed in an unexpected area in the input config file.\n";
else Log::warn("Device manager","An action is placed in an unexpected area in the input config file.");
}
}
break;
@ -534,7 +536,7 @@ bool DeviceManager::deserialize()
if(UserConfigParams::logMisc())
{
printf("Found %d keyboard and %d gamepad configurations.\n",
Log::info("Device manager","Found %d keyboard and %d gamepad configurations.",
m_keyboard_configs.size(), m_gamepad_configs.size());
}
@ -557,7 +559,7 @@ bool DeviceManager::deserialize()
void DeviceManager::serialize()
{
static std::string filepath = file_manager->getUserConfigFile(INPUT_FILE_NAME);
if(UserConfigParams::logMisc()) printf("Serializing input.xml...\n");
if(UserConfigParams::logMisc()) Log::info("Device manager","Serializing input.xml...");
std::ofstream configfile;
@ -565,8 +567,7 @@ void DeviceManager::serialize()
if(!configfile.is_open())
{
std::cerr << "Failed to open " << filepath.c_str()
<< " for writing, controls won't be saved\n";
Log::error("Device manager","Failed to open %s for writing, controls won't be saved",filepath.c_str());
return;
}
@ -584,7 +585,7 @@ void DeviceManager::serialize()
configfile << "</input>\n";
configfile.close();
if(UserConfigParams::logMisc()) printf("Serialization complete.\n\n");
if(UserConfigParams::logMisc()) Log::info("Device manager","Serialization complete.");
} // serialize
// -----------------------------------------------------------------------------

View File

@ -946,7 +946,6 @@ void World::updateHighscores(int* best_highscore_rank, int* best_finish_time,
continue;
if (!m_karts[index[pos]]->hasFinishedRace()) continue;
assert(index[pos] >= 0);
assert(index[pos] < m_karts.size());
Kart *k = (Kart*)m_karts[index[pos]];

View File

@ -87,7 +87,7 @@ private:
// --------------------------------------------------------------------
const UserPointer *getUserPointer(unsigned int n) const
{
assert(n>=0 && n<=1);
assert(n<=1);
return m_up[n];
} // getUserPointer
// --------------------------------------------------------------------

View File

@ -142,7 +142,7 @@ void RaceManager::setLocalKartInfo(unsigned int player_id,
const std::string& kart)
{
assert(kart.size() > 0);
assert(0<=player_id && player_id <m_local_player_karts.size());
assert(player_id <m_local_player_karts.size());
assert(kart_properties_manager->getKart(kart) != NULL);
const PlayerProfile* profile = StateManager::get()->getActivePlayerProfile(player_id);
@ -156,7 +156,7 @@ void RaceManager::setLocalKartInfo(unsigned int player_id,
*/
void RaceManager::setLocalKartSoccerTeam(unsigned int player_id, SoccerTeam team)
{
assert(0<=player_id && player_id <m_local_player_karts.size());
assert(player_id <m_local_player_karts.size());
m_local_player_karts[player_id].setSoccerTeam(team);
}