diff options
author | Ladislav Zezula <ladislav.zezula@avg.com> | 2015-05-28 13:49:23 +0200 |
---|---|---|
committer | Ladislav Zezula <ladislav.zezula@avg.com> | 2015-05-28 13:49:23 +0200 |
commit | 1b38ceb0d4bb4ae32cb93c295e3ef493b91f9a78 (patch) | |
tree | 5634e1d3fd17386975db1c0d4e95176db098bc1f /src/SFileAttributes.cpp | |
parent | c26e12c79f2a5e0c092de4a62565bdae4bf5a7dd (diff) |
+ Fixed defects found by Coverity (well, most of them)
Diffstat (limited to 'src/SFileAttributes.cpp')
-rw-r--r-- | src/SFileAttributes.cpp | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/SFileAttributes.cpp b/src/SFileAttributes.cpp index d37d83c..dc13b2c 100644 --- a/src/SFileAttributes.cpp +++ b/src/SFileAttributes.cpp @@ -378,22 +378,26 @@ int SAttrLoadAttributes(TMPQArchive * ha) { // Retrieve and check size of the (attributes) file cbAttrFile = SFileGetFileSize(hFile, NULL); - - // Size of the (attributes) might be 1 byte less than expected - // See GetSizeOfAttributesFile for more info - pbAttrFile = STORM_ALLOC(BYTE, cbAttrFile + 1); - if(pbAttrFile != NULL) + + // Integer overflow check + if((cbAttrFile + 1) > cbAttrFile) { - // Set the last byte to 0 in case the size should be 1 byte greater - pbAttrFile[cbAttrFile] = 0; + // Size of the (attributes) might be 1 byte less than expected + // See GetSizeOfAttributesFile for more info + pbAttrFile = STORM_ALLOC(BYTE, cbAttrFile + 1); + if(pbAttrFile != NULL) + { + // Set the last byte to 0 in case the size should be 1 byte greater + pbAttrFile[cbAttrFile] = 0; - // Load the entire file to memory - SFileReadFile(hFile, pbAttrFile, cbAttrFile, &dwBytesRead, NULL); - if(dwBytesRead == cbAttrFile) - nError = LoadAttributesFile(ha, pbAttrFile, cbAttrFile); + // Load the entire file to memory + SFileReadFile(hFile, pbAttrFile, cbAttrFile, &dwBytesRead, NULL); + if(dwBytesRead == cbAttrFile) + nError = LoadAttributesFile(ha, pbAttrFile, cbAttrFile); - // Free the buffer - STORM_FREE(pbAttrFile); + // Free the buffer + STORM_FREE(pbAttrFile); + } } // Close the attributes file |