aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorunknown <E:\Ladik\Mail>2015-01-18 17:34:34 +0100
committerunknown <E:\Ladik\Mail>2015-01-18 17:34:34 +0100
commit23ffb9d452397b3ca1742854ebbeeeb305b98bc4 (patch)
tree796714e507d68e8ecbda7313deb163fa586cd1a5 /src
parente9842c38cf9c55f682b2a411cea84ee59d69ec92 (diff)
+ More paratemer checking to make nitpickers happy
Diffstat (limited to 'src')
-rw-r--r--src/SFileAddFile.cpp13
-rw-r--r--src/SFileExtractFile.cpp29
-rw-r--r--src/SFileOpenArchive.cpp16
-rw-r--r--src/SFileReadFile.cpp4
-rw-r--r--src/SFileVerify.cpp3
5 files changed, 40 insertions, 25 deletions
diff --git a/src/SFileAddFile.cpp b/src/SFileAddFile.cpp
index 524fb50..0878ab7 100644
--- a/src/SFileAddFile.cpp
+++ b/src/SFileAddFile.cpp
@@ -725,11 +725,20 @@ bool WINAPI SFileCreateFile(
nError = ERROR_INVALID_PARAMETER;
}
- // Check for MPQs that have invalid block table size
+ // The number of files must not overflow the maximum
// Example: size of block table: 0x41, size of hash table: 0x40
if(nError == ERROR_SUCCESS)
{
- if(ha->dwFileTableSize > ha->dwMaxFileCount)
+ DWORD dwReservedFiles = ha->dwReservedFiles;
+
+ if(dwReservedFiles == 0)
+ {
+ dwReservedFiles += ha->dwFileFlags1 ? 1 : 0;
+ dwReservedFiles += ha->dwFileFlags2 ? 1 : 0;
+ dwReservedFiles += ha->dwFileFlags3 ? 1 : 0;
+ }
+
+ if((ha->dwFileTableSize + dwReservedFiles) > ha->dwMaxFileCount)
nError = ERROR_DISK_FULL;
}
diff --git a/src/SFileExtractFile.cpp b/src/SFileExtractFile.cpp
index 314d8ff..cabde49 100644
--- a/src/SFileExtractFile.cpp
+++ b/src/SFileExtractFile.cpp
@@ -34,26 +34,23 @@ bool WINAPI SFileExtractFile(HANDLE hMpq, const char * szToExtract, const TCHAR
}
// Copy the file's content
- if(nError == ERROR_SUCCESS)
+ while(nError == ERROR_SUCCESS)
{
char szBuffer[0x1000];
- DWORD dwTransferred;
+ DWORD dwTransferred = 0;
- for(;;)
- {
- // dwTransferred is only set to nonzero if something has been read.
- // nError can be ERROR_SUCCESS or ERROR_HANDLE_EOF
- if(!SFileReadFile(hMpqFile, szBuffer, sizeof(szBuffer), &dwTransferred, NULL))
- nError = GetLastError();
- if(nError == ERROR_HANDLE_EOF)
- nError = ERROR_SUCCESS;
- if(dwTransferred == 0)
- break;
+ // dwTransferred is only set to nonzero if something has been read.
+ // nError can be ERROR_SUCCESS or ERROR_HANDLE_EOF
+ if(!SFileReadFile(hMpqFile, szBuffer, sizeof(szBuffer), &dwTransferred, NULL))
+ nError = GetLastError();
+ if(nError == ERROR_HANDLE_EOF)
+ nError = ERROR_SUCCESS;
+ if(dwTransferred == 0)
+ break;
- // If something has been actually read, write it
- if(!FileStream_Write(pLocalFile, NULL, szBuffer, dwTransferred))
- nError = GetLastError();
- }
+ // If something has been actually read, write it
+ if(!FileStream_Write(pLocalFile, NULL, szBuffer, dwTransferred))
+ nError = GetLastError();
}
// Close the files
diff --git a/src/SFileOpenArchive.cpp b/src/SFileOpenArchive.cpp
index 19d18c2..80ac9e1 100644
--- a/src/SFileOpenArchive.cpp
+++ b/src/SFileOpenArchive.cpp
@@ -470,12 +470,12 @@ bool WINAPI SFileSetDownloadCallback(HANDLE hMpq, SFILE_DOWNLOAD_CALLBACK Downlo
bool WINAPI SFileFlushArchive(HANDLE hMpq)
{
- TMPQArchive * ha = (TMPQArchive *)hMpq;
+ TMPQArchive * ha;
int nResultError = ERROR_SUCCESS;
int nError;
// Do nothing if 'hMpq' is bad parameter
- if(!IsValidMpqHandle(hMpq))
+ if((ha = IsValidMpqHandle(hMpq)) == NULL)
{
SetLastError(ERROR_INVALID_HANDLE);
return false;
@@ -540,8 +540,15 @@ bool WINAPI SFileFlushArchive(HANDLE hMpq)
bool WINAPI SFileCloseArchive(HANDLE hMpq)
{
- TMPQArchive * ha = (TMPQArchive *)hMpq;
- bool bResult;
+ TMPQArchive * ha = IsValidMpqHandle(hMpq);
+ bool bResult = false;
+
+ // Only if the handle is valid
+ if(ha == NULL)
+ {
+ SetLastError(ERROR_INVALID_HANDLE);
+ return false;
+ }
// Invalidate the add file callback so it won't be called
// when saving (listfile) and (attributes)
@@ -555,4 +562,3 @@ bool WINAPI SFileCloseArchive(HANDLE hMpq)
FreeArchiveHandle(ha);
return bResult;
}
-
diff --git a/src/SFileReadFile.cpp b/src/SFileReadFile.cpp
index 6884f55..75c5508 100644
--- a/src/SFileReadFile.cpp
+++ b/src/SFileReadFile.cpp
@@ -659,7 +659,9 @@ bool WINAPI SFileReadFile(HANDLE hFile, void * pvBuffer, DWORD dwToRead, LPDWORD
DWORD dwBytesRead = 0; // Number of bytes read
int nError = ERROR_SUCCESS;
- // Keep compilers happy
+ // Always zero the result
+ if(pdwRead != NULL)
+ *pdwRead = 0;
lpOverlapped = lpOverlapped;
// Check valid parameters
diff --git a/src/SFileVerify.cpp b/src/SFileVerify.cpp
index 4267016..8cf138a 100644
--- a/src/SFileVerify.cpp
+++ b/src/SFileVerify.cpp
@@ -563,7 +563,6 @@ static DWORD VerifyFile(
HANDLE hFile = NULL;
DWORD dwVerifyResult = 0;
DWORD dwTotalBytes = 0;
- DWORD dwBytesRead;
DWORD dwCrc32 = 0;
//
@@ -622,6 +621,8 @@ static DWORD VerifyFile(
// Go through entire file and update both CRC32 and MD5
for(;;)
{
+ DWORD dwBytesRead = 0;
+
// Read data from file
SFileReadFile(hFile, Buffer, sizeof(Buffer), &dwBytesRead, NULL);
if(dwBytesRead == 0)