diff options
| author | j4ck.fr0st <j4ck.fr0st@gmail.com> | 2010-02-03 20:29:49 +0000 |
|---|---|---|
| committer | j4ck.fr0st <j4ck.fr0st@gmail.com> | 2010-02-03 20:29:49 +0000 |
| commit | 43051ffe4100a8f59bd93dcb3002a3455a117018 (patch) | |
| tree | f8b3ad4befcc79db200ae8ccac486f36c67a8631 /Source/Core/Common | |
| parent | 8281564b5c0ffb124c89c8c055fd96ff448ac9d4 (diff) | |
some cleanup, housekeeping for error cases and increased a few buffer sizes that are overflown by its content.
Thanks to Fatalis for the initial patch and pointing us to cppcheck.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5004 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/Common')
| -rw-r--r-- | Source/Core/Common/Src/FileUtil.cpp | 1 | ||||
| -rw-r--r-- | Source/Core/Common/Src/SysConf.cpp | 27 | ||||
| -rw-r--r-- | Source/Core/Common/Src/SysConf.h | 4 |
3 files changed, 23 insertions, 9 deletions
diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index e0b64e1f43..34c93d82cf 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -481,6 +481,7 @@ bool DeleteDirRecursively(const char *directory) FindClose(hFind); #else } + closedir(dirp); #endif File::DeleteDir(directory); diff --git a/Source/Core/Common/Src/SysConf.cpp b/Source/Core/Common/Src/SysConf.cpp index 3477770816..c9a86e6e15 100644 --- a/Source/Core/Common/Src/SysConf.cpp +++ b/Source/Core/Common/Src/SysConf.cpp @@ -49,18 +49,32 @@ SysConf::~SysConf() bool SysConf::LoadFromFile(const char *filename)
{
+ // Basic check
+ u64 size = File::GetSize(filename);
+ if (size == 0)
+ return false; //most likely: file does not exist
+ if (size != SYSCONF_SIZE)
+ {
+ PanicAlert("Your SYSCONF file is the wrong size - should be 0x%04x (but is 0x%04x)",
+ SYSCONF_SIZE, size);
+ return false;
+ }
FILE* f = fopen(filename, "rb");
if (f == NULL)
return false;
-
- // Basic check
- if (File::GetSize(filename) != SYSCONF_SIZE)
+ bool result = LoadFromFileInternal(f);
+ if (result)
{
- PanicAlert("Your SYSCONF file is the wrong size - should be 0x%04x", SYSCONF_SIZE);
- return false;
+ // OK, done!
+ m_Filename = filename;
}
+ fclose(f);
+ return result;
+}
+bool SysConf::LoadFromFileInternal(FILE *f)
+{
// Fill in infos
if (fread(&m_Header.version, sizeof(m_Header.version), 1, f) != 1) return false;
if (fread(&m_Header.numEntries, sizeof(m_Header.numEntries), 1, f) != 1) return false;
@@ -123,9 +137,6 @@ bool SysConf::LoadFromFile(const char *filename) }
}
- // OK!, done!
- m_Filename = filename;
- fclose(f);
return true;
}
diff --git a/Source/Core/Common/Src/SysConf.h b/Source/Core/Common/Src/SysConf.h index e3bba9336f..d91cc471ac 100644 --- a/Source/Core/Common/Src/SysConf.h +++ b/Source/Core/Common/Src/SysConf.h @@ -71,7 +71,7 @@ public: bool IsValid() { return m_IsValid; }
- void Reload();
+ void Reload();
template<class T>
T GetData(const char* sectionName)
@@ -122,6 +122,8 @@ public: bool Save();
bool SaveToFile(const char* filename);
bool LoadFromFile(const char* filename);
+private:
+ bool LoadFromFileInternal(FILE *f);
};
#endif // __SYSCONF_MANAGER_h__
|
