Be paranoid about g_system being set

svn-id: r36131
This commit is contained in:
Max Horn 2009-01-29 22:09:06 +00:00
parent 164a099c7f
commit 7eaafd933f
6 changed files with 16 additions and 8 deletions

View file

@ -460,6 +460,7 @@ void SearchManager::clear() {
// Always keep system specific archives in the SearchManager. // Always keep system specific archives in the SearchManager.
// But we give them a lower priority than the default priority (which is 0), // But we give them a lower priority than the default priority (which is 0),
// so that archives added by client code are searched first. // so that archives added by client code are searched first.
if (g_system)
g_system->addSysArchivesToSearchSet(*this, -1); g_system->addSysArchivesToSearchSet(*this, -1);
// Add the current dir as a very last resort. // Add the current dir as a very last resort.

View file

@ -65,9 +65,11 @@ bool ConfigFile::loadFromFile(const String &filename) {
} }
bool ConfigFile::loadFromSaveFile(const char *filename) { bool ConfigFile::loadFromSaveFile(const char *filename) {
assert(g_system);
SaveFileManager *saveFileMan = g_system->getSavefileManager(); SaveFileManager *saveFileMan = g_system->getSavefileManager();
SeekableReadStream *loadFile; SeekableReadStream *loadFile;
assert(saveFileMan);
if (!(loadFile = saveFileMan->openForLoading(filename))) if (!(loadFile = saveFileMan->openForLoading(filename)))
return false; return false;
@ -189,9 +191,11 @@ bool ConfigFile::saveToFile(const String &filename) {
} }
bool ConfigFile::saveToSaveFile(const char *filename) { bool ConfigFile::saveToSaveFile(const char *filename) {
assert(g_system);
SaveFileManager *saveFileMan = g_system->getSavefileManager(); SaveFileManager *saveFileMan = g_system->getSavefileManager();
WriteStream *saveFile; WriteStream *saveFile;
assert(saveFileMan);
if (!(saveFile = saveFileMan->openForSaving(filename))) if (!(saveFile = saveFileMan->openForSaving(filename)))
return false; return false;

View file

@ -62,6 +62,7 @@ ConfigManager::ConfigManager()
void ConfigManager::loadDefaultConfigFile() { void ConfigManager::loadDefaultConfigFile() {
// Open the default config file // Open the default config file
assert(g_system);
SeekableReadStream *stream = g_system->createConfigReadStream(); SeekableReadStream *stream = g_system->createConfigReadStream();
_filename.clear(); // clear the filename to indicate that we are using the default config file _filename.clear(); // clear the filename to indicate that we are using the default config file
@ -190,6 +191,7 @@ void ConfigManager::flushToDisk() {
if (_filename.empty()) { if (_filename.empty()) {
// Write to the default config file // Write to the default config file
assert(g_system);
stream = g_system->createConfigWriteStream(); stream = g_system->createConfigWriteStream();
if (!stream) // If writing to the config file is not possible, do nothing if (!stream) // If writing to the config file is not possible, do nothing
return; return;

View file

@ -37,6 +37,7 @@ FSNode::FSNode(AbstractFSNode *realNode)
} }
FSNode::FSNode(const Common::String &p) { FSNode::FSNode(const Common::String &p) {
assert(g_system);
FilesystemFactory *factory = g_system->getFilesystemFactory(); FilesystemFactory *factory = g_system->getFilesystemFactory();
AbstractFSNode *tmp = 0; AbstractFSNode *tmp = 0;

View file

@ -29,6 +29,7 @@
namespace Common { namespace Common {
Mutex::Mutex() { Mutex::Mutex() {
assert(g_system);
_mutex = g_system->createMutex(); _mutex = g_system->createMutex();
} }

View file

@ -472,17 +472,16 @@ static void debugHelper(const char *in_buf, bool caret = true) {
g_engine->errorString(in_buf, buf, STRINGBUFLEN); g_engine->errorString(in_buf, buf, STRINGBUFLEN);
} else { } else {
strncpy(buf, in_buf, STRINGBUFLEN); strncpy(buf, in_buf, STRINGBUFLEN);
buf[STRINGBUFLEN-1] = '\0';
} }
buf[STRINGBUFLEN-2] = '\0';
buf[STRINGBUFLEN-1] = '\0';
if (caret)
printf("%s\n", buf);
else
printf("%s", buf);
#if defined( USE_WINDBG )
if (caret) if (caret)
strcat(buf, "\n"); strcat(buf, "\n");
fprintf(stdout, "%s", buf); // FIXME: Use fputs instead
#if defined( USE_WINDBG )
#if defined( _WIN32_WCE ) #if defined( _WIN32_WCE )
TCHAR buf_unicode[1024]; TCHAR buf_unicode[1024];
MultiByteToWideChar(CP_ACP, 0, buf, strlen(buf) + 1, buf_unicode, sizeof(buf_unicode)); MultiByteToWideChar(CP_ACP, 0, buf, strlen(buf) + 1, buf_unicode, sizeof(buf_unicode));