From 1b38ceb0d4bb4ae32cb93c295e3ef493b91f9a78 Mon Sep 17 00:00:00 2001 From: Ladislav Zezula Date: Thu, 28 May 2015 13:49:23 +0200 Subject: + Fixed defects found by Coverity (well, most of them) --- src/SFileOpenArchive.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/SFileOpenArchive.cpp') 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); } -- cgit v1.2.3