aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/scicore/decompress0.cpp
diff options
context:
space:
mode:
authorFilippos Karapetis2009-03-02 10:34:31 +0000
committerFilippos Karapetis2009-03-02 10:34:31 +0000
commitf72e3354e8fffd20057a29ea5c5a905a1ee1869c (patch)
tree1a869e8dd04bc90b366ead5695a4e1df014612df /engines/sci/scicore/decompress0.cpp
parent310036788af846adb818ab12b42aaf425ebde03d (diff)
downloadscummvm-rg350-f72e3354e8fffd20057a29ea5c5a905a1ee1869c.tar.gz
scummvm-rg350-f72e3354e8fffd20057a29ea5c5a905a1ee1869c.tar.bz2
scummvm-rg350-f72e3354e8fffd20057a29ea5c5a905a1ee1869c.zip
Slight cleanup
svn-id: r39068
Diffstat (limited to 'engines/sci/scicore/decompress0.cpp')
-rw-r--r--engines/sci/scicore/decompress0.cpp45
1 files changed, 19 insertions, 26 deletions
diff --git a/engines/sci/scicore/decompress0.cpp b/engines/sci/scicore/decompress0.cpp
index 2a715fd334..def3a20ea3 100644
--- a/engines/sci/scicore/decompress0.cpp
+++ b/engines/sci/scicore/decompress0.cpp
@@ -288,39 +288,24 @@ int decompress0(Resource *result, Common::ReadStream &stream, int sci_version) {
compressedLength, result->size);
#endif
+ bool overflow = false;
+
switch (compressionMethod) {
case 0: // no compression
- if (result->size != compressedLength) {
- free(result->data);
- result->data = NULL;
- result->status = SCI_STATUS_NOMALLOC;
- free(buffer);
- return SCI_ERROR_DECOMPRESSION_OVERFLOW;
- }
- memcpy(result->data, buffer, compressedLength);
- result->status = SCI_STATUS_ALLOCATED;
+ if (result->size != compressedLength)
+ overflow = true;
+ else
+ memcpy(result->data, buffer, compressedLength);
break;
case 1: // LZW compression
- if (decrypt1(result->data, buffer, result->size, compressedLength)) {
- free(result->data);
- result->data = 0; // So that we know that it didn't work
- result->status = SCI_STATUS_NOMALLOC;
- free(buffer);
- return SCI_ERROR_DECOMPRESSION_OVERFLOW;
- }
- result->status = SCI_STATUS_ALLOCATED;
+ if (decrypt1(result->data, buffer, result->size, compressedLength))
+ overflow = true;
break;
case 2: // Some sort of Huffman encoding
- if (decrypt2(result->data, buffer, result->size, compressedLength)) {
- free(result->data);
- result->data = 0; // So that we know that it didn't work
- result->status = SCI_STATUS_NOMALLOC;
- free(buffer);
- return SCI_ERROR_DECOMPRESSION_OVERFLOW;
- }
- result->status = SCI_STATUS_ALLOCATED;
+ if (decrypt2(result->data, buffer, result->size, compressedLength))
+ overflow = true;
break;
default:
@@ -334,8 +319,16 @@ int decompress0(Resource *result, Common::ReadStream &stream, int sci_version) {
return SCI_ERROR_UNKNOWN_COMPRESSION;
}
- free(buffer);
+ if (overflow) {
+ free(result->data);
+ result->data = 0; // So that we know that it didn't work
+ result->status = SCI_STATUS_NOMALLOC;
+ free(buffer);
+ return SCI_ERROR_DECOMPRESSION_OVERFLOW;
+ }
+ result->status = SCI_STATUS_ALLOCATED;
+ free(buffer);
return 0;
}