diff options
| author | Tannin <devnull@localhost> | 2015-02-25 18:38:01 +0100 |
|---|---|---|
| committer | Tannin <devnull@localhost> | 2015-02-25 18:38:01 +0100 |
| commit | 6479f972dccaabb3afadb570583a4269e8a785e4 (patch) | |
| tree | b36ec1afc65e123b893215a2529bb20c25041adb /src/shared | |
| parent | e01ab940b0d76bfec8d7037ee56938780a74dc5b (diff) | |
tons of code cleanup and minor fixes to harden the code (mostly suggestions from static code analysis)
Diffstat (limited to 'src/shared')
| -rw-r--r-- | src/shared/directoryentry.cpp | 8 | ||||
| -rw-r--r-- | src/shared/error_report.cpp | 3 | ||||
| -rw-r--r-- | src/shared/fallout3info.h | 31 | ||||
| -rw-r--r-- | src/shared/leaktrace.cpp | 2 | ||||
| -rw-r--r-- | src/shared/stackdata.cpp | 1 | ||||
| -rw-r--r-- | src/shared/util.cpp | 13 |
6 files changed, 17 insertions, 41 deletions
diff --git a/src/shared/directoryentry.cpp b/src/shared/directoryentry.cpp index 5cf75752..9a864245 100644 --- a/src/shared/directoryentry.cpp +++ b/src/shared/directoryentry.cpp @@ -235,7 +235,8 @@ void FileEntry::addOrigin(int origin, FILETIME fileTime, const std::wstring &arc m_Origin = origin;
m_FileTime = fileTime;
m_Archive = archive;
- } else if (m_Parent->getOriginByID(origin).getPriority() > m_Parent->getOriginByID(m_Origin).getPriority()) {
+ } else if ((m_Parent != nullptr)
+ && (m_Parent->getOriginByID(origin).getPriority() > m_Parent->getOriginByID(m_Origin).getPriority())) {
if (std::find(m_Alternatives.begin(), m_Alternatives.end(), m_Origin) == m_Alternatives.end()) {
m_Alternatives.push_back(m_Origin);
}
@@ -253,7 +254,8 @@ void FileEntry::addOrigin(int origin, FILETIME fileTime, const std::wstring &arc // already an origin
return;
}
- if (m_Parent->getOriginByID(*iter).getPriority() < m_Parent->getOriginByID(origin).getPriority()) {
+ if ((m_Parent != nullptr)
+ && (m_Parent->getOriginByID(*iter).getPriority() < m_Parent->getOriginByID(origin).getPriority())) {
m_Alternatives.insert(iter, origin);
found = true;
break;
@@ -508,7 +510,7 @@ void DirectoryEntry::addFiles(FilesOrigin &origin, wchar_t *buffer, int bufferOf {
WIN32_FIND_DATAW findData;
- _snwprintf(buffer + bufferOffset, MAXPATH_UNICODE - bufferOffset, L"\\*");
+ _snwprintf_s(buffer + bufferOffset, MAXPATH_UNICODE - bufferOffset, _TRUNCATE, L"\\*");
HANDLE searchHandle = nullptr;
diff --git a/src/shared/error_report.cpp b/src/shared/error_report.cpp index c9277c1b..6d091630 100644 --- a/src/shared/error_report.cpp +++ b/src/shared/error_report.cpp @@ -46,8 +46,7 @@ void reportError(LPCWSTR format, ...) va_list argList;
va_start(argList, format);
-
- _vsnwprintf(buffer, 1024, format, argList);
+ _vsnwprintf_s(buffer, 1024, format, argList);
va_end(argList);
MessageBoxW(nullptr, buffer, L"Error", MB_OK | MB_ICONERROR);
diff --git a/src/shared/fallout3info.h b/src/shared/fallout3info.h index 1f3a381d..6e6a7b85 100644 --- a/src/shared/fallout3info.h +++ b/src/shared/fallout3info.h @@ -43,38 +43,7 @@ public: virtual std::wstring getGameName() const { return L"Fallout 3"; }
virtual std::wstring getGameShortName() const { return L"Fallout3"; }
-/*
- virtual std::wstring getInvalidationBSA()
- {
- return L"Fallout - Invalidation.bsa";
- }
-
- virtual bool isInvalidationBSA(const std::wstring &bsaName)
- {
- static LPCWSTR invalidation[] = { L"Fallout - AI!.bsa", L"Fallout - Invalidation.bsa", nullptr };
-
- for (int i = 0; invalidation[i] != nullptr; ++i) {
- if (wcscmp(bsaName.c_str(), invalidation[i]) == 0) {
- return true;
- }
- }
- return false;
- }
-
- virtual std::vector<std::wstring> getVanillaBSAs()
- {
- return boost::assign::list_of (L"Fallout - Textures.bsa")
- (L"Fallout - Meshes.bsa")
- (L"Fallout - Voices.bsa")
- (L"Fallout - Sound.bsa")
- (L"Fallout - MenuVoices.bsa")
- (L"Fallout - Misc.bsa");
- }
- virtual std::vector<std::wstring> getPrimaryPlugins()
- {
- return boost::assign::list_of(L"fallout3.esm");
- }*/
virtual std::vector<std::wstring> getDLCPlugins();
virtual std::vector<std::wstring> getSavegameAttachmentExtensions();
diff --git a/src/shared/leaktrace.cpp b/src/shared/leaktrace.cpp index 0d99b82e..73786c6b 100644 --- a/src/shared/leaktrace.cpp +++ b/src/shared/leaktrace.cpp @@ -34,7 +34,7 @@ static struct __TraceData { iter->second.size(), iter->first.toString().c_str());
printf("Addresses: ");
for (int i = 0; i < (std::min<int>)(5, iter->second.size()); ++i) {
- printf("%p, ", iter->second[i]);
+ printf("%p, ", reinterpret_cast<void*>(iter->second[i]));
}
printf("\n");
}
diff --git a/src/shared/stackdata.cpp b/src/shared/stackdata.cpp index 2f8bfc4e..43acd90a 100644 --- a/src/shared/stackdata.cpp +++ b/src/shared/stackdata.cpp @@ -135,7 +135,6 @@ void StackData::initTrace() { }
}
-#pragma warning( enable : 4748 )
bool MOShared::operator==(const StackData &LHS, const StackData &RHS) {
if (LHS.m_Count != RHS.m_Count) {
diff --git a/src/shared/util.cpp b/src/shared/util.cpp index ceed3a34..2ce88eca 100644 --- a/src/shared/util.cpp +++ b/src/shared/util.cpp @@ -55,7 +55,10 @@ std::string ToString(const std::wstring &source, bool utf8) {
std::string result;
if (source.length() > 0) {
- UINT codepage = utf8 ? CP_UTF8 : GetACP();
+ UINT codepage = CP_UTF8;
+ if (!utf8) {
+ codepage = AreFileApisANSI() ? GetACP() : GetOEMCP();
+ }
int sizeRequired = ::WideCharToMultiByte(codepage, 0, &source[0], -1, nullptr, 0, nullptr, nullptr);
if (sizeRequired == 0) {
throw windows_error("failed to convert string to multibyte");
@@ -73,7 +76,10 @@ std::wstring ToWString(const std::string &source, bool utf8) {
std::wstring result;
if (source.length() > 0) {
- UINT codepage = utf8 ? CP_UTF8 : GetACP();
+ UINT codepage = CP_UTF8;
+ if (!utf8) {
+ codepage = AreFileApisANSI() ? GetACP() : GetOEMCP();
+ }
int sizeRequired = ::MultiByteToWideChar(codepage, 0, source.c_str(), source.length(), nullptr, 0);
if (sizeRequired == 0) {
throw windows_error("failed to convert string to wide character");
@@ -113,7 +119,7 @@ std::wstring ToLower(const std::wstring &text) VS_FIXEDFILEINFO GetFileVersion(const std::wstring &fileName)
{
- DWORD handle;
+ DWORD handle = 0UL;
DWORD size = ::GetFileVersionInfoSizeW(fileName.c_str(), &handle);
if (size == 0) {
throw windows_error("failed to determine file version info size");
@@ -121,6 +127,7 @@ VS_FIXEDFILEINFO GetFileVersion(const std::wstring &fileName) void *buffer = new char[size];
try {
+ handle = 0UL;
if (!::GetFileVersionInfoW(fileName.c_str(), handle, size, buffer)) {
throw windows_error("failed to determine file version info");
}
|
