[sword-svn] r2020 - trunk/src/modules/common
dglassey at www.crosswire.org
dglassey at www.crosswire.org
Fri Dec 8 03:57:12 MST 2006
Author: dglassey
Date: 2006-12-08 03:57:11 -0700 (Fri, 08 Dec 2006)
New Revision: 2020
Modified:
trunk/src/modules/common/zipcomprs.cpp
trunk/src/modules/common/zverse.cpp
Log:
patch from Martin Gruner to fix compression
- fix one unchecked pointer access in zverse.cpp, based on Joachim's
suggestion
- allow the return value of the zip uncompression code to be used correctly.
Now uncompression will detect that it has corrupt data (when deciphering
with a wrong key) and return an empty string in that case.
Modified: trunk/src/modules/common/zipcomprs.cpp
===================================================================
--- trunk/src/modules/common/zipcomprs.cpp 2006-12-06 18:40:43 UTC (rev 2019)
+++ trunk/src/modules/common/zipcomprs.cpp 2006-12-08 10:57:11 UTC (rev 2020)
@@ -79,7 +79,7 @@
if (len)
{
//printf("Doing compress\n");
- if (compress((Bytef*)zbuf, &zlen, (const Bytef*)buf, len)!=Z_OK)
+ if (compress((Bytef*)zbuf, &zlen, (const Bytef*)buf, len) != Z_OK)
{
printf("ERROR in compression\n");
}
@@ -89,7 +89,7 @@
}
else
{
- fprintf(stderr, "No buffer to compress\n");
+ fprintf(stderr, "ERROR: no buffer to compress\n");
}
delete [] zbuf;
free (buf);
@@ -144,15 +144,18 @@
unsigned long blen = zlen*20; // trust compression is less than 1000%
char *buf = new char[blen];
//printf("Doing decompress {%s}\n", zbuf);
- if (uncompress((Bytef*)buf, &blen, (Bytef*)zbuf, zlen) != Z_OK) {
- fprintf(stderr, "no room in outbuffer to during decompression. see zipcomp.cpp\n");
+ slen = 0;
+ switch (uncompress((Bytef*)buf, &blen, (Bytef*)zbuf, zlen)){
+ case Z_OK: SendChars(buf, blen); slen = blen; break;
+ case Z_MEM_ERROR: fprintf(stderr, "ERROR: not enough memory during decompression.\n"); break;
+ case Z_BUF_ERROR: fprintf(stderr, "ERROR: not enough room in the out buffer during decompression.\n"); break;
+ case Z_DATA_ERROR: fprintf(stderr, "ERROR: corrupt data during decompression.\n"); break;
+ default: fprintf(stderr, "ERROR: an unknown error occured during decompression.\n"); break;
}
- SendChars(buf, blen);
delete [] buf;
- slen = blen;
}
else {
- fprintf(stderr, "No buffer to decompress!\n");
+ fprintf(stderr, "ERROR: no buffer to decompress!\n");
}
//printf("Finished decoding\n");
free (zbuf);
Modified: trunk/src/modules/common/zverse.cpp
===================================================================
--- trunk/src/modules/common/zverse.cpp 2006-12-06 18:40:43 UTC (rev 2019)
+++ trunk/src/modules/common/zverse.cpp 2006-12-08 10:57:11 UTC (rev 2020)
@@ -256,13 +256,12 @@
void zVerse::zReadText(char testmt, long start, unsigned short size, SWBuf &inBuf) {
inBuf = "";
- inBuf.setFillByte(0);
- inBuf.setSize(size+1);
- if (size > 0) {
- if (cacheBuf)
- strncpy(inBuf.getRawData(), &(cacheBuf[start]), size);
+ if ( (size > 0) && cacheBuf && ((start+size) <= strlen(cacheBuf)) ){ //TODO: optimize this, remove strlen
+ inBuf.setFillByte(0);
+ inBuf.setSize(size+1);
+ strncpy(inBuf.getRawData(), &(cacheBuf[start]), size);
+ inBuf.setSize(strlen(inBuf.c_str()));
}
- inBuf.setSize(strlen(inBuf.c_str()));
}
More information about the sword-cvs
mailing list