diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/keys/treekeyidx.cpp | 6 | ||||
-rw-r--r-- | src/modules/comments/rawcom/rawcom.cpp | 98 | ||||
-rw-r--r-- | src/modules/comments/zcom/zcom.cpp | 103 | ||||
-rw-r--r-- | src/modules/common/rawstr.cpp | 2 | ||||
-rw-r--r-- | src/modules/texts/rawtext/rawtext.cpp | 118 | ||||
-rw-r--r-- | src/modules/texts/ztext/ztext.cpp | 119 | ||||
-rw-r--r-- | src/utilfuns/zlib/infcodes.c | 214 | ||||
-rw-r--r-- | src/utilfuns/zlib/inffast.c | 196 |
8 files changed, 360 insertions, 496 deletions
diff --git a/src/keys/treekeyidx.cpp b/src/keys/treekeyidx.cpp index e12a458..04831d2 100644 --- a/src/keys/treekeyidx.cpp +++ b/src/keys/treekeyidx.cpp @@ -1,7 +1,7 @@ /****************************************************************************** * versekey.h - code for class 'versekey'- a standard Biblical verse key * - * $Id: treekeyidx.cpp,v 1.12 2002/10/08 00:36:00 scribe Exp $ + * $Id: treekeyidx.cpp,v 1.13 2002/10/21 00:30:37 scribe Exp $ * * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society @@ -341,7 +341,7 @@ char TreeKeyIdx::getTreeNodeFromIdxOffset(long ioffset, TreeNode *node) const { if (ioffset < 0) { ioffset = 0; - error = 7777; // out of bounds but still position to 0; + error = 77; // out of bounds but still position to 0; } node->offset = ioffset; @@ -350,7 +350,7 @@ char TreeKeyIdx::getTreeNodeFromIdxOffset(long ioffset, TreeNode *node) const { lseek(idxfd->getFd(), ioffset, SEEK_SET); if (read(idxfd->getFd(), &offset, 4) == 4) { offset = swordtoarch32(offset); - error = (error == 7777) ? KEYERR_OUTOFBOUNDS : 0; + error = (error == 77) ? KEYERR_OUTOFBOUNDS : 0; getTreeNodeFromDatOffset(offset, node); } else { diff --git a/src/modules/comments/rawcom/rawcom.cpp b/src/modules/comments/rawcom/rawcom.cpp index de400d6..c9cfcd5 100644 --- a/src/modules/comments/rawcom/rawcom.cpp +++ b/src/modules/comments/rawcom/rawcom.cpp @@ -54,15 +54,7 @@ RawCom::~RawCom() char *RawCom::getRawEntry() { long start = 0; unsigned short size = 0; - VerseKey *key = 0; - - try { - key = SWDYNAMIC_CAST(VerseKey, this->key); - } - catch ( ... ) {} - if (!key) - key = new VerseKey(this->key); - + VerseKey *key = &getVerseKey(); findoffset(key->Testament(), key->Index(), &start, &size); entrySize = size; // support getEntrySize call @@ -85,9 +77,6 @@ char *RawCom::getRawEntry() { if (!isUnicode()) preptext(entrybuf); - if (key != this->key) - delete key; - return entrybuf; } @@ -103,14 +92,7 @@ char *RawCom::getRawEntry() { void RawCom::increment(int steps) { long start; unsigned short size; - VerseKey *tmpkey = 0; - - try { - tmpkey = SWDYNAMIC_CAST(VerseKey, key); - } - catch ( ... ) {} - if (!tmpkey) - tmpkey = new VerseKey(key); + VerseKey *tmpkey = &getVerseKey(); findoffset(tmpkey->Testament(), tmpkey->Index(), &start, &size); @@ -120,15 +102,7 @@ void RawCom::increment(int steps) { unsigned short lastsize = size; SWKey lasttry = *tmpkey; (steps > 0) ? (*key)++ : (*key)--; - if (tmpkey != key) - delete tmpkey; - tmpkey = 0; - try { - tmpkey = SWDYNAMIC_CAST(VerseKey, key); - } - catch ( ... ) {} - if (!tmpkey) - tmpkey = new VerseKey(key); + tmpkey = &getVerseKey(); if ((error = key->Error())) { *key = lastgood; @@ -145,41 +119,18 @@ void RawCom::increment(int steps) { } } error = (error) ? KEYERR_OUTOFBOUNDS : 0; - - if (tmpkey != key) - delete tmpkey; } void RawCom::setEntry(const char *inbuf, long len) { - VerseKey *key = 0; - // see if we have a VerseKey * or decendant - try { - key = SWDYNAMIC_CAST(VerseKey, this->key); - } - catch ( ... ) {} - // if we don't have a VerseKey * decendant, create our own - if (!key) - key = new VerseKey(this->key); - + VerseKey *key = &getVerseKey(); settext(key->Testament(), key->Index(), inbuf, len); - - if (this->key != key) // free our key if we created a VerseKey - delete key; } void RawCom::linkEntry(const SWKey *inkey) { - VerseKey *destkey = 0; + VerseKey *destkey = &getVerseKey(); const VerseKey *srckey = 0; - // see if we have a VerseKey * or decendant - try { - destkey = SWDYNAMIC_CAST(VerseKey, this->key); - } - catch ( ... ) {} - // if we don't have a VerseKey * decendant, create our own - if (!destkey) - destkey = new VerseKey(this->key); // see if we have a VerseKey * or decendant try { @@ -192,9 +143,6 @@ void RawCom::linkEntry(const SWKey *inkey) { linkentry(destkey->Testament(), destkey->Index(), srckey->Index()); - if (this->key != destkey) // free our key if we created a VerseKey - delete destkey; - if (inkey != srckey) // free our key if we created a VerseKey delete srckey; } @@ -208,19 +156,37 @@ void RawCom::linkEntry(const SWKey *inkey) { void RawCom::deleteEntry() { - VerseKey *key = 0; + VerseKey *key = &getVerseKey(); + settext(key->Testament(), key->Index(), ""); +} + +VerseKey &RawCom::getVerseKey() { + static VerseKey tmpVK; + VerseKey *key; + // see if we have a VerseKey * or decendant try { key = SWDYNAMIC_CAST(VerseKey, this->key); } - catch ( ... ) {} - if (!key) - key = new VerseKey(this->key); - - settext(key->Testament(), key->Index(), ""); - - if (key != this->key) - delete key; + catch ( ... ) { } + if (!key) { + ListKey *lkTest = 0; + try { + lkTest = SWDYNAMIC_CAST(ListKey, this->key); + } + catch ( ... ) { } + if (lkTest) { + try { + key = SWDYNAMIC_CAST(VerseKey, lkTest->GetElement()); + } + catch ( ... ) { } + } + } + if (!key) { + tmpVK = *(this->key); + return tmpVK; + } + else return *key; } diff --git a/src/modules/comments/zcom/zcom.cpp b/src/modules/comments/zcom/zcom.cpp index 7d5d3c2..b3a10de 100644 --- a/src/modules/comments/zcom/zcom.cpp +++ b/src/modules/comments/zcom/zcom.cpp @@ -58,15 +58,7 @@ zCom::~zCom() { char *zCom::getRawEntry() { long start = 0; unsigned short size = 0; - VerseKey *key = 0; - - try { - key = SWDYNAMIC_CAST(VerseKey, this->key); - } - catch ( ... ) {} - // if we don't have a VerseKey * decendant, create our own - if (!key) - key = new VerseKey(this->key); + VerseKey *key = &getVerseKey(); findoffset(key->Testament(), key->Index(), &start, &size); entrySize = size; // support getEntrySize call @@ -87,9 +79,6 @@ char *zCom::getRawEntry() { if (!isUnicode()) preptext(entrybuf); - if (this->key != key) // free our key if we created a VerseKey - delete key; - return entrybuf; } @@ -113,16 +102,7 @@ bool zCom::sameBlock(VerseKey *k1, VerseKey *k2) { } void zCom::setEntry(const char *inbuf, long len) { - VerseKey *key = 0; - // see if we have a VerseKey * or decendant - try { - key = SWDYNAMIC_CAST(VerseKey, this->key); - } - catch ( ... ) {} - // if we don't have a VerseKey * decendant, create our own - if (!key) - key = new VerseKey(this->key); - + VerseKey *key = &getVerseKey(); // see if we've jumped across blocks since last write if (lastWriteKey) { @@ -135,23 +115,12 @@ void zCom::setEntry(const char *inbuf, long len) { settext(key->Testament(), key->Index(), inbuf, len); lastWriteKey = (VerseKey *)key->clone(); // must delete - - if (this->key != key) // free our key if we created a VerseKey - delete key; } void zCom::linkEntry(const SWKey *inkey) { - VerseKey *destkey = 0; + VerseKey *destkey = &getVerseKey(); const VerseKey *srckey = 0; - // see if we have a VerseKey * or decendant - try { - destkey = SWDYNAMIC_CAST(VerseKey, this->key); - } - catch ( ... ) {} - // if we don't have a VerseKey * decendant, create our own - if (!destkey) - destkey = new VerseKey(this->key); // see if we have a VerseKey * or decendant try { @@ -165,9 +134,6 @@ void zCom::linkEntry(const SWKey *inkey) { linkentry(destkey->Testament(), destkey->Index(), srckey->Index()); - if (this->key != destkey) // free our key if we created a VerseKey - delete destkey; - if (inkey != srckey) // free our key if we created a VerseKey delete srckey; } @@ -180,19 +146,8 @@ void zCom::linkEntry(const SWKey *inkey) { void zCom::deleteEntry() { - VerseKey *key = 0; - - try { - key = SWDYNAMIC_CAST(VerseKey, this->key); - } - catch ( ... ) {} - if (!key) - key = new VerseKey(this->key); - + VerseKey *key = &getVerseKey(); settext(key->Testament(), key->Index(), ""); - - if (key != this->key) - delete key; } @@ -207,14 +162,7 @@ void zCom::deleteEntry() { void zCom::increment(int steps) { long start; unsigned short size; - VerseKey *tmpkey = 0; - - try { - tmpkey = SWDYNAMIC_CAST(VerseKey, key); - } - catch ( ... ) {} - if (!tmpkey) - tmpkey = new VerseKey(key); + VerseKey *tmpkey = &getVerseKey(); findoffset(tmpkey->Testament(), tmpkey->Index(), &start, &size); @@ -224,15 +172,7 @@ void zCom::increment(int steps) { unsigned short lastsize = size; SWKey lasttry = *tmpkey; (steps > 0) ? (*key)++ : (*key)--; - if (tmpkey != key) - delete tmpkey; - tmpkey = 0; - try { - tmpkey = SWDYNAMIC_CAST(VerseKey, key); - } - catch ( ... ) {} - if (!tmpkey) - tmpkey = new VerseKey(key); + tmpkey = &getVerseKey(); if ((error = key->Error())) { *key = lastgood; @@ -249,9 +189,36 @@ void zCom::increment(int steps) { } } error = (error) ? KEYERR_OUTOFBOUNDS : 0; +} + - if (tmpkey != key) - delete tmpkey; +VerseKey &zCom::getVerseKey() { + static VerseKey tmpVK; + VerseKey *key; + // see if we have a VerseKey * or decendant + try { + key = SWDYNAMIC_CAST(VerseKey, this->key); + } + catch ( ... ) { } + if (!key) { + ListKey *lkTest = 0; + try { + lkTest = SWDYNAMIC_CAST(ListKey, this->key); + } + catch ( ... ) { } + if (lkTest) { + try { + key = SWDYNAMIC_CAST(VerseKey, lkTest->GetElement()); + } + catch ( ... ) { } + } + } + if (!key) { + tmpVK = *(this->key); + return tmpVK; + } + else return *key; } + SWORD_NAMESPACE_END diff --git a/src/modules/common/rawstr.cpp b/src/modules/common/rawstr.cpp index a9f9c1d..eeb3bf8 100644 --- a/src/modules/common/rawstr.cpp +++ b/src/modules/common/rawstr.cpp @@ -171,7 +171,7 @@ signed char RawStr::findoffset(const char *ikey, long *start, unsigned short *si if (*ikey) { headoff = 0; - key = new char [ strlen(ikey) + 10 ]; // just in case toupper needs a few extra + key = new char [ (strlen(ikey)*2) + 10 ]; // just in case toupper needs a few extra strcpy(key, ikey); toupperstr_utf8(key); diff --git a/src/modules/texts/rawtext/rawtext.cpp b/src/modules/texts/rawtext/rawtext.cpp index fe14e9b..ef7742a 100644 --- a/src/modules/texts/rawtext/rawtext.cpp +++ b/src/modules/texts/rawtext/rawtext.cpp @@ -77,6 +77,35 @@ RawText::~RawText() } +VerseKey &RawText::getVerseKey() { + static VerseKey tmpVK; + VerseKey *key; + // see if we have a VerseKey * or decendant + try { + key = SWDYNAMIC_CAST(VerseKey, this->key); + } + catch ( ... ) { } + if (!key) { + ListKey *lkTest = 0; + try { + lkTest = SWDYNAMIC_CAST(ListKey, this->key); + } + catch ( ... ) { } + if (lkTest) { + try { + key = SWDYNAMIC_CAST(VerseKey, lkTest->GetElement()); + } + catch ( ... ) { } + } + } + if (!key) { + tmpVK = *(this->key); + return tmpVK; + } + else return *key; +} + + /****************************************************************************** * RawText::getRawEntry - Returns the correct verse when char * cast * is requested @@ -87,18 +116,9 @@ RawText::~RawText() char *RawText::getRawEntry() { long start = 0; unsigned short size = 0; - VerseKey *key = 0; + VerseKey &key = getVerseKey(); - // see if we have a VerseKey * or decendant - try { - key = SWDYNAMIC_CAST(VerseKey, this->key); - } - catch ( ... ) { } - // if we don't have a VerseKey * decendant, create our own - if (!key) - key = new VerseKey(this->key); - - findoffset(key->Testament(), key->Index(), &start, &size); + findoffset(key.Testament(), key.Index(), &start, &size); entrySize = size; // support getEntrySize call unsigned long newsize = (size + 2) * FILTERPAD; @@ -110,18 +130,15 @@ char *RawText::getRawEntry() { } *entrybuf = 0; - readtext(key->Testament(), start, (size + 2), entrybuf); + readtext(key.Testament(), start, (size + 2), entrybuf); entrybuf[size] = 0; rawFilter(entrybuf, size, 0); // hack, decipher - rawFilter(entrybuf, size*FILTERPAD, key); + rawFilter(entrybuf, size*FILTERPAD, &key); if (!isUnicode()) preptext(entrybuf); - if (this->key != key) // free our key if we created a VerseKey - delete key; - return entrybuf; } @@ -458,34 +475,14 @@ ListKey &RawText::Search(const char *istr, int searchType, int flags, SWKey *sco void RawText::setEntry(const char *inbuf, long len) { - VerseKey *key = 0; - // see if we have a VerseKey * or decendant - try { - key = SWDYNAMIC_CAST(VerseKey, this->key); - } - catch ( ... ) {} - // if we don't have a VerseKey * decendant, create our own - if (!key) - key = new VerseKey(this->key); - - settext(key->Testament(), key->Index(), inbuf, len); - - if (this->key != key) // free our key if we created a VerseKey - delete key; + VerseKey &key = getVerseKey(); + settext(key.Testament(), key.Index(), inbuf, len); } void RawText::linkEntry(const SWKey *inkey) { - VerseKey *destkey = 0; + VerseKey &destkey = getVerseKey(); const VerseKey *srckey = 0; - // see if we have a VerseKey * or decendant - try { - destkey = SWDYNAMIC_CAST(VerseKey, this->key); - } - catch ( ... ) {} - // if we don't have a VerseKey * decendant, create our own - if (!destkey) - destkey = new VerseKey(this->key); // see if we have a VerseKey * or decendant try { @@ -496,10 +493,7 @@ void RawText::linkEntry(const SWKey *inkey) { if (!srckey) srckey = new VerseKey(inkey); - linkentry(destkey->Testament(), destkey->Index(), srckey->Index()); - - if (this->key != destkey) // free our key if we created a VerseKey - delete destkey; + linkentry(destkey.Testament(), destkey.Index(), srckey->Index()); if (inkey != srckey) // free our key if we created a VerseKey delete srckey; @@ -513,20 +507,8 @@ void RawText::linkEntry(const SWKey *inkey) { */ void RawText::deleteEntry() { - - VerseKey *key = 0; - - try { - key = SWDYNAMIC_CAST(VerseKey, this->key); - } - catch ( ... ) {} - if (!key) - key = new VerseKey(this->key); - - settext(key->Testament(), key->Index(), ""); - - if (key != this->key) - delete key; + VerseKey &key = getVerseKey(); + settext(key.Testament(), key.Index(), ""); } /****************************************************************************** @@ -540,14 +522,7 @@ void RawText::deleteEntry() { void RawText::increment(int steps) { long start; unsigned short size; - VerseKey *tmpkey = 0; - - try { - tmpkey = SWDYNAMIC_CAST(VerseKey, key); - } - catch ( ... ) {} - if (!tmpkey) - tmpkey = new VerseKey(key); + VerseKey *tmpkey = &getVerseKey(); findoffset(tmpkey->Testament(), tmpkey->Index(), &start, &size); @@ -557,15 +532,7 @@ void RawText::increment(int steps) { unsigned short lastsize = size; SWKey lasttry = *tmpkey; (steps > 0) ? (*key)++ : (*key)--; - if (tmpkey != key) - delete tmpkey; - tmpkey = 0; - try { - tmpkey = SWDYNAMIC_CAST(VerseKey, key); - } - catch ( ... ) {} - if (!tmpkey) - tmpkey = new VerseKey(key); + tmpkey = &getVerseKey(); if ((error = key->Error())) { *key = lastgood; @@ -582,9 +549,6 @@ void RawText::increment(int steps) { } } error = (error) ? KEYERR_OUTOFBOUNDS : 0; - - if (tmpkey != key) - delete tmpkey; } SWORD_NAMESPACE_END diff --git a/src/modules/texts/ztext/ztext.cpp b/src/modules/texts/ztext/ztext.cpp index fe90216..00793c2 100644 --- a/src/modules/texts/ztext/ztext.cpp +++ b/src/modules/texts/ztext/ztext.cpp @@ -63,18 +63,9 @@ char *zText::getRawEntry() { long start = 0; unsigned short size = 0; - VerseKey *key = 0; + VerseKey &key = getVerseKey(); - // see if we have a VerseKey * or decendant - try { - key = SWDYNAMIC_CAST(VerseKey, this->key); - } - catch ( ... ) {} - // if we don't have a VerseKey * decendant, create our own - if (!key) - key = new VerseKey(this->key); - - findoffset(key->Testament(), key->Index(), &start, &size); + findoffset(key.Testament(), key.Index(), &start, &size); entrySize = size; // support getEntrySize call unsigned long newsize = (size + 2) * FILTERPAD; @@ -86,16 +77,13 @@ char *zText::getRawEntry() } *entrybuf = 0; - zreadtext(key->Testament(), start, (size + 2), entrybuf); + zreadtext(key.Testament(), start, (size + 2), entrybuf); - rawFilter(entrybuf, size*FILTERPAD, key); + rawFilter(entrybuf, size*FILTERPAD, &key); if (!isUnicode()) preptext(entrybuf); - if (this->key != key) // free our key if we created a VerseKey - delete key; - return entrybuf; } @@ -120,45 +108,25 @@ bool zText::sameBlock(VerseKey *k1, VerseKey *k2) { void zText::setEntry(const char *inbuf, long len) { - VerseKey *key = 0; - // see if we have a VerseKey * or decendant - try { - key = SWDYNAMIC_CAST(VerseKey, this->key); - } - catch ( ... ) {} - // if we don't have a VerseKey * decendant, create our own - if (!key) - key = new VerseKey(this->key); - + VerseKey &key = getVerseKey(); // see if we've jumped across blocks since last write if (lastWriteKey) { - if (!sameBlock(lastWriteKey, key)) { + if (!sameBlock(lastWriteKey, &key)) { flushCache(); } delete lastWriteKey; } - settext(key->Testament(), key->Index(), inbuf, len); - - lastWriteKey = (VerseKey *)key->clone(); // must delete + settext(key.Testament(), key.Index(), inbuf, len); - if (this->key != key) // free our key if we created a VerseKey - delete key; + lastWriteKey = (VerseKey *)key.clone(); // must delete } void zText::linkEntry(const SWKey *inkey) { - VerseKey *destkey = 0; + VerseKey &destkey = getVerseKey(); const VerseKey *srckey = 0; - // see if we have a VerseKey * or decendant - try { - destkey = SWDYNAMIC_CAST(VerseKey, this->key); - } - catch ( ... ) {} - // if we don't have a VerseKey * decendant, create our own - if (!destkey) - destkey = new VerseKey(this->key); // see if we have a VerseKey * or decendant try { @@ -170,10 +138,7 @@ void zText::linkEntry(const SWKey *inkey) { if (!srckey) srckey = new VerseKey(inkey); - linkentry(destkey->Testament(), destkey->Index(), srckey->Index()); - - if (this->key != destkey) // free our key if we created a VerseKey - delete destkey; + linkentry(destkey.Testament(), destkey.Index(), srckey->Index()); if (inkey != srckey) // free our key if we created a VerseKey delete srckey; @@ -187,19 +152,9 @@ void zText::linkEntry(const SWKey *inkey) { void zText::deleteEntry() { - VerseKey *key = 0; + VerseKey &key = getVerseKey(); - try { - key = SWDYNAMIC_CAST(VerseKey, this->key); - } - catch ( ... ) {} - if (!key) - key = new VerseKey(this->key); - - settext(key->Testament(), key->Index(), ""); - - if (key != this->key) - delete key; + settext(key.Testament(), key.Index(), ""); } @@ -213,14 +168,7 @@ void zText::deleteEntry() { void zText::increment(int steps) { long start; unsigned short size; - VerseKey *tmpkey = 0; - - try { - tmpkey = SWDYNAMIC_CAST(VerseKey, key); - } - catch ( ... ) {} - if (!tmpkey) - tmpkey = new VerseKey(key); + VerseKey *tmpkey = &getVerseKey(); findoffset(tmpkey->Testament(), tmpkey->Index(), &start, &size); @@ -230,15 +178,7 @@ void zText::increment(int steps) { unsigned short lastsize = size; SWKey lasttry = *tmpkey; (steps > 0) ? (*key)++ : (*key)--; - if (tmpkey != key) - delete tmpkey; - tmpkey = 0; - try { - tmpkey = SWDYNAMIC_CAST(VerseKey, key); - } - catch ( ... ) {} - if (!tmpkey) - tmpkey = new VerseKey(key); + tmpkey = &getVerseKey(); if ((error = key->Error())) { *key = lastgood; @@ -256,9 +196,36 @@ void zText::increment(int steps) { } } error = (error) ? KEYERR_OUTOFBOUNDS : 0; +} + - if (tmpkey != key) - delete tmpkey; +VerseKey &zText::getVerseKey() { + static VerseKey tmpVK; + VerseKey *key; + // see if we have a VerseKey * or decendant + try { + key = SWDYNAMIC_CAST(VerseKey, this->key); + } + catch ( ... ) { } + if (!key) { + ListKey *lkTest = 0; + try { + lkTest = SWDYNAMIC_CAST(ListKey, this->key); + } + catch ( ... ) { } + if (lkTest) { + try { + key = SWDYNAMIC_CAST(VerseKey, lkTest->GetElement()); + } + catch ( ... ) { } + } + } + if (!key) { + tmpVK = *(this->key); + return tmpVK; + } + else return *key; } + SWORD_NAMESPACE_END diff --git a/src/utilfuns/zlib/infcodes.c b/src/utilfuns/zlib/infcodes.c index 9abe541..0d54ea7 100644 --- a/src/utilfuns/zlib/infcodes.c +++ b/src/utilfuns/zlib/infcodes.c @@ -92,7 +92,7 @@ int r; uInt n; /* bytes available there */ Bytef *q; /* output window write pointer */ uInt m; /* bytes to end of window or read pointer */ - Bytef *f; /* pointer to copy strings from */ + unsigned long csf; /* pointer to copy strings from */ inflate_codes_statef *c = s->sub.decode.codes; /* codes state */ /* copy input/output information to locals (UPDATE macro restores) */ @@ -103,120 +103,120 @@ int r; { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */ case START: /* x: set up for LEN */ #ifndef SLOW - if (m >= 258 && n >= 10) - { - UPDATE - r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z); - LOAD - if (r != Z_OK) - { - c->mode = r == Z_STREAM_END ? WASH : BADCODE; - break; - } - } + if (m >= 258 && n >= 10) + { + UPDATE + r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z); + LOAD + if (r != Z_OK) + { + c->mode = r == Z_STREAM_END ? WASH : BADCODE; + break; + } + } #endif /* !SLOW */ - c->sub.code.need = c->lbits; - c->sub.code.tree = c->ltree; - c->mode = LEN; + c->sub.code.need = c->lbits; + c->sub.code.tree = c->ltree; + c->mode = LEN; case LEN: /* i: get length/literal/eob next */ - j = c->sub.code.need; - NEEDBITS(j) - t = c->sub.code.tree + ((uInt)b & inflate_mask[j]); - DUMPBITS(t->bits) - e = (uInt)(t->exop); - if (e == 0) /* literal */ - { - c->sub.lit = t->base; - Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? - "inflate: literal '%c'\n" : - "inflate: literal 0x%02x\n", t->base)); - c->mode = LIT; - break; - } - if (e & 16) /* length */ - { - c->sub.copy.get = e & 15; - c->len = t->base; - c->mode = LENEXT; - break; - } - if ((e & 64) == 0) /* next table */ - { - c->sub.code.need = e; - c->sub.code.tree = t + t->base; - break; - } - if (e & 32) /* end of block */ - { - Tracevv((stderr, "inflate: end of block\n")); - c->mode = WASH; - break; - } - c->mode = BADCODE; /* invalid code */ - z->msg = (char*)"invalid literal/length code"; - r = Z_DATA_ERROR; - LEAVE + j = c->sub.code.need; + NEEDBITS(j) + t = c->sub.code.tree + ((uInt)b & inflate_mask[j]); + DUMPBITS(t->bits) + e = (uInt)(t->exop); + if (e == 0) /* literal */ + { + c->sub.lit = t->base; + Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? + "inflate: literal '%c'\n" : + "inflate: literal 0x%02x\n", t->base)); + c->mode = LIT; + break; + } + if (e & 16) /* length */ + { + c->sub.copy.get = e & 15; + c->len = t->base; + c->mode = LENEXT; + break; + } + if ((e & 64) == 0) /* next table */ + { + c->sub.code.need = e; + c->sub.code.tree = t + t->base; + break; + } + if (e & 32) /* end of block */ + { + Tracevv((stderr, "inflate: end of block\n")); + c->mode = WASH; + break; + } + c->mode = BADCODE; /* invalid code */ + z->msg = (char*)"invalid literal/length code"; + r = Z_DATA_ERROR; + LEAVE case LENEXT: /* i: getting length extra (have base) */ - j = c->sub.copy.get; - NEEDBITS(j) - c->len += (uInt)b & inflate_mask[j]; - DUMPBITS(j) - c->sub.code.need = c->dbits; - c->sub.code.tree = c->dtree; - Tracevv((stderr, "inflate: length %u\n", c->len)); - c->mode = DIST; + j = c->sub.copy.get; + NEEDBITS(j) + c->len += (uInt)b & inflate_mask[j]; + DUMPBITS(j) + c->sub.code.need = c->dbits; + c->sub.code.tree = c->dtree; + Tracevv((stderr, "inflate: length %u\n", c->len)); + c->mode = DIST; case DIST: /* i: get distance next */ - j = c->sub.code.need; - NEEDBITS(j) - t = c->sub.code.tree + ((uInt)b & inflate_mask[j]); - DUMPBITS(t->bits) - e = (uInt)(t->exop); - if (e & 16) /* distance */ - { - c->sub.copy.get = e & 15; - c->sub.copy.dist = t->base; - c->mode = DISTEXT; - break; - } - if ((e & 64) == 0) /* next table */ - { - c->sub.code.need = e; - c->sub.code.tree = t + t->base; - break; - } - c->mode = BADCODE; /* invalid code */ - z->msg = (char*)"invalid distance code"; - r = Z_DATA_ERROR; - LEAVE + j = c->sub.code.need; + NEEDBITS(j) + t = c->sub.code.tree + ((uInt)b & inflate_mask[j]); + DUMPBITS(t->bits) + e = (uInt)(t->exop); + if (e & 16) /* distance */ + { + c->sub.copy.get = e & 15; + c->sub.copy.dist = t->base; + c->mode = DISTEXT; + break; + } + if ((e & 64) == 0) /* next table */ + { + c->sub.code.need = e; + c->sub.code.tree = t + t->base; + break; + } + c->mode = BADCODE; /* invalid code */ + z->msg = (char*)"invalid distance code"; + r = Z_DATA_ERROR; + LEAVE case DISTEXT: /* i: getting distance extra */ - j = c->sub.copy.get; - NEEDBITS(j) - c->sub.copy.dist += (uInt)b & inflate_mask[j]; - DUMPBITS(j) - Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist)); - c->mode = COPY; + j = c->sub.copy.get; + NEEDBITS(j) + c->sub.copy.dist += (uInt)b & inflate_mask[j]; + DUMPBITS(j) + Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist)); + c->mode = COPY; case COPY: /* o: copying bytes in window, waiting for space */ - f = q - c->sub.copy.dist; - while (f < s->window) /* modulo window size-"while" instead */ - f += s->end - s->window; /* of "if" handles invalid distances */ - while (c->len) - { - NEEDOUT - OUTBYTE(*f++) - if (f == s->end) - f = s->window; - c->len--; - } - c->mode = START; - break; + csf = (unsigned long)q - c->sub.copy.dist; + while (csf < (unsigned long)s->window) /* modulo window size-"while" instead */ + csf += (unsigned long)(s->end - s->window); /* of "if" handles invalid distances */ + while (c->len) + { + NEEDOUT + OUTBYTE(*(Bytef *)csf++) + if (csf == (unsigned long)s->end) + csf = (unsigned long)s->window; + c->len--; + } + c->mode = START; + break; case LIT: /* o: got literal, waiting for output space */ - NEEDOUT - OUTBYTE(c->sub.lit) - c->mode = START; - break; + NEEDOUT + OUTBYTE(c->sub.lit) + c->mode = START; + break; case WASH: /* o: got eob, possibly more output */ - if (k > 7) /* return unused byte, if any */ - { + if (k > 7) /* return unused byte, if any */ + { Assert(k < 16, "inflate_codes grabbed too many bytes") k -= 8; n++; diff --git a/src/utilfuns/zlib/inffast.c b/src/utilfuns/zlib/inffast.c index aa7f1d4..a7ebc64 100644 --- a/src/utilfuns/zlib/inffast.c +++ b/src/utilfuns/zlib/inffast.c @@ -44,7 +44,7 @@ z_streamp z; uInt md; /* mask for distance tree */ uInt c; /* bytes to copy */ uInt d; /* distance back to copy from */ - Bytef *r; /* copy source pointer */ + unsigned long csp; /* copy source pointer */ /* load input, output, bit values */ LOAD @@ -59,107 +59,107 @@ z_streamp z; GRABBITS(20) /* max bits for literal/length code */ if ((e = (t = tl + ((uInt)b & ml))->exop) == 0) { - DUMPBITS(t->bits) - Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? - "inflate: * literal '%c'\n" : - "inflate: * literal 0x%02x\n", t->base)); - *q++ = (Byte)t->base; - m--; - continue; + DUMPBITS(t->bits) + Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? + "inflate: * literal '%c'\n" : + "inflate: * literal 0x%02x\n", t->base)); + *q++ = (Byte)t->base; + m--; + continue; } do { - DUMPBITS(t->bits) - if (e & 16) - { - /* get extra bits for length */ - e &= 15; - c = t->base + ((uInt)b & inflate_mask[e]); - DUMPBITS(e) - Tracevv((stderr, "inflate: * length %u\n", c)); + DUMPBITS(t->bits) + if (e & 16) + { + /* get extra bits for length */ + e &= 15; + c = t->base + ((uInt)b & inflate_mask[e]); + DUMPBITS(e) + Tracevv((stderr, "inflate: * length %u\n", c)); - /* decode distance base of block to copy */ - GRABBITS(15); /* max bits for distance code */ - e = (t = td + ((uInt)b & md))->exop; - do { - DUMPBITS(t->bits) - if (e & 16) - { - /* get extra bits to add to distance base */ - e &= 15; - GRABBITS(e) /* get extra bits (up to 13) */ - d = t->base + ((uInt)b & inflate_mask[e]); - DUMPBITS(e) - Tracevv((stderr, "inflate: * distance %u\n", d)); + /* decode distance base of block to copy */ + GRABBITS(15); /* max bits for distance code */ + e = (t = td + ((uInt)b & md))->exop; + do { + DUMPBITS(t->bits) + if (e & 16) + { + /* get extra bits to add to distance base */ + e &= 15; + GRABBITS(e) /* get extra bits (up to 13) */ + d = t->base + ((uInt)b & inflate_mask[e]); + DUMPBITS(e) + Tracevv((stderr, "inflate: * distance %u\n", d)); - /* do the copy */ - m -= c; - r = q - d; - if (r < s->window) /* wrap if needed */ - { - do { - r += s->end - s->window; /* force pointer in window */ - } while (r < s->window); /* covers invalid distances */ - e = s->end - r; - if (c > e) - { - c -= e; /* wrapped copy */ - do { - *q++ = *r++; - } while (--e); - r = s->window; - do { - *q++ = *r++; - } while (--c); - } - else /* normal copy */ - { - *q++ = *r++; c--; - *q++ = *r++; c--; - do { - *q++ = *r++; - } while (--c); - } - } - else /* normal copy */ - { - *q++ = *r++; c--; - *q++ = *r++; c--; - do { - *q++ = *r++; - } while (--c); - } - break; - } - else if ((e & 64) == 0) - { - t += t->base; - e = (t += ((uInt)b & inflate_mask[e]))->exop; - } - else - { - z->msg = (char*)"invalid distance code"; - UNGRAB - UPDATE - return Z_DATA_ERROR; - } - } while (1); - break; - } - if ((e & 64) == 0) - { - t += t->base; - if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0) - { - DUMPBITS(t->bits) - Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? - "inflate: * literal '%c'\n" : - "inflate: * literal 0x%02x\n", t->base)); - *q++ = (Byte)t->base; - m--; - break; - } - } - else if (e & 32) + /* do the copy */ + m -= c; + csp = (unsigned long)q - d; + if (csp < (unsigned long)s->window) /* wrap if needed */ + { + do { + csp += (unsigned long)(s->end - s->window); /* force pointer in window */ + } while (csp < (unsigned long)s->window); /* covers invalid distances */ + e = (unsigned long)s->end - csp; + if (c > e) + { + c -= e; /* wrapped copy */ + do { + *q++ = *(Bytef *)csp++; + } while (--e); + csp = s->window; + do { + *q++ = *(Bytef *)csp++; + } while (--c); + } + else /* normal copy */ + { + *q++ = *(Bytef *)csp++; c--; + *q++ = *(Bytef *)csp++; c--; + do { + *q++ = *(Bytef *)csp++; + } while (--c); + } + } + else /* normal copy */ + { + *q++ = *(Bytef *)csp++; c--; + *q++ = *(Bytef *)csp++; c--; + do { + *q++ = *(Bytef *)csp++; + } while (--c); + } + break; + } + else if ((e & 64) == 0) + { + t += t->base; + e = (t += ((uInt)b & inflate_mask[e]))->exop; + } + else + { + z->msg = (char*)"invalid distance code"; + UNGRAB + UPDATE + return Z_DATA_ERROR; + } + } while (1); + break; + } + if ((e & 64) == 0) + { + t += t->base; + if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0) + { + DUMPBITS(t->bits) + Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? + "inflate: * literal '%c'\n" : + "inflate: * literal 0x%02x\n", t->base)); + *q++ = (Byte)t->base; + m--; + break; + } + } + else if (e & 32) { Tracevv((stderr, "inflate: * end of block\n")); UNGRAB |