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/SFileAddFile.cpp | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'src/SFileAddFile.cpp') diff --git a/src/SFileAddFile.cpp b/src/SFileAddFile.cpp index ea3c5f9..b70eeb1 100644 --- a/src/SFileAddFile.cpp +++ b/src/SFileAddFile.cpp @@ -435,7 +435,7 @@ int SFileAddFile_Init( // Allocate the TMPQFile entry for newly added file hf = CreateWritableHandle(ha, dwFileSize); if(hf == NULL) - nError = GetLastError(); + return false; // Allocate file entry in the MPQ if(nError == ERROR_SUCCESS) @@ -902,26 +902,21 @@ bool WINAPI SFileAddFileEx( // Check parameters if(hMpq == NULL || szFileName == NULL || *szFileName == 0) - nError = ERROR_INVALID_PARAMETER; - - // Open added file - if(nError == ERROR_SUCCESS) { - pStream = FileStream_OpenFile(szFileName, STREAM_FLAG_READ_ONLY | STREAM_PROVIDER_FLAT | BASE_PROVIDER_FILE); - if(pStream == NULL) - nError = GetLastError(); + SetLastError(ERROR_INVALID_PARAMETER); + return false; } - // Get the file size and file time - if(nError == ERROR_SUCCESS) - { - FileStream_GetTime(pStream, &FileTime); - FileStream_GetSize(pStream, &FileSize); - - // Files bigger than 4GB cannot be added to MPQ - if(FileSize >> 32) - nError = ERROR_DISK_FULL; - } + // Open added file + pStream = FileStream_OpenFile(szFileName, STREAM_FLAG_READ_ONLY | STREAM_PROVIDER_FLAT | BASE_PROVIDER_FILE); + if(pStream == NULL) + return false; + + // Files bigger than 4GB cannot be added to MPQ + FileStream_GetTime(pStream, &FileTime); + FileStream_GetSize(pStream, &FileSize); + if(FileSize >> 32) + nError = ERROR_DISK_FULL; // Allocate data buffer for reading from the source file if(nError == ERROR_SUCCESS) -- cgit v1.2.3