aboutsummaryrefslogtreecommitdiff
path: root/src/SFileOpenArchive.cpp
diff options
context:
space:
mode:
authorLadislav Zezula <ladislav.zezula@avg.com>2015-05-28 13:49:23 +0200
committerLadislav Zezula <ladislav.zezula@avg.com>2015-05-28 13:49:23 +0200
commit1b38ceb0d4bb4ae32cb93c295e3ef493b91f9a78 (patch)
tree5634e1d3fd17386975db1c0d4e95176db098bc1f /src/SFileOpenArchive.cpp
parentc26e12c79f2a5e0c092de4a62565bdae4bf5a7dd (diff)
+ Fixed defects found by Coverity (well, most of them)
Diffstat (limited to 'src/SFileOpenArchive.cpp')
-rw-r--r--src/SFileOpenArchive.cpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/SFileOpenArchive.cpp b/src/SFileOpenArchive.cpp
index 35fd4dd..d62b98f 100644
--- a/src/SFileOpenArchive.cpp
+++ b/src/SFileOpenArchive.cpp
@@ -158,30 +158,28 @@ bool WINAPI SFileOpenArchive(
TFileEntry * pFileEntry;
ULONGLONG FileSize = 0; // Size of the file
LPBYTE pbHeaderBuffer = NULL; // Buffer for searching MPQ header
+ DWORD dwStreamFlags = (dwFlags & STREAM_FLAGS_MASK);
bool bIsWarcraft3Map = false;
int nError = ERROR_SUCCESS;
// Verify the parameters
if(szMpqName == NULL || *szMpqName == 0 || phMpq == NULL)
- nError = ERROR_INVALID_PARAMETER;
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return false;
+ }
// One time initialization of MPQ cryptography
InitializeMpqCryptography();
dwPriority = dwPriority;
- // Open the MPQ archive file
- if(nError == ERROR_SUCCESS)
- {
- DWORD dwStreamFlags = (dwFlags & STREAM_FLAGS_MASK);
-
- // If not forcing MPQ v 1.0, also use file bitmap
- dwStreamFlags |= (dwFlags & MPQ_OPEN_FORCE_MPQ_V1) ? 0 : STREAM_FLAG_USE_BITMAP;
+ // If not forcing MPQ v 1.0, also use file bitmap
+ dwStreamFlags |= (dwFlags & MPQ_OPEN_FORCE_MPQ_V1) ? 0 : STREAM_FLAG_USE_BITMAP;
- // Initialize the stream
- pStream = FileStream_OpenFile(szMpqName, dwStreamFlags);
- if(pStream == NULL)
- nError = GetLastError();
- }
+ // Open the MPQ archive file
+ pStream = FileStream_OpenFile(szMpqName, dwStreamFlags);
+ if(pStream == NULL)
+ return false;
// Check the file size. There must be at least 0x20 bytes
if(nError == ERROR_SUCCESS)
@@ -450,7 +448,8 @@ bool WINAPI SFileOpenArchive(
// Free the header buffer
if(pbHeaderBuffer != NULL)
STORM_FREE(pbHeaderBuffer);
- *phMpq = ha;
+ if(phMpq != NULL)
+ *phMpq = ha;
return (nError == ERROR_SUCCESS);
}