[Scummvm-cvs-logs] SF.net SVN: scummvm:[39068] scummvm/trunk/engines/sci/scicore/decompress0. cpp
thebluegr at users.sourceforge.net
thebluegr at users.sourceforge.net
Mon Mar 2 11:34:31 CET 2009
Revision: 39068
http://scummvm.svn.sourceforge.net/scummvm/?rev=39068&view=rev
Author: thebluegr
Date: 2009-03-02 10:34:31 +0000 (Mon, 02 Mar 2009)
Log Message:
-----------
Slight cleanup
Modified Paths:
--------------
scummvm/trunk/engines/sci/scicore/decompress0.cpp
Modified: scummvm/trunk/engines/sci/scicore/decompress0.cpp
===================================================================
--- scummvm/trunk/engines/sci/scicore/decompress0.cpp 2009-03-02 09:16:03 UTC (rev 39067)
+++ scummvm/trunk/engines/sci/scicore/decompress0.cpp 2009-03-02 10:34:31 UTC (rev 39068)
@@ -288,39 +288,24 @@
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 @@
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;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list