diff --git a/src/zopfli/deflate.c b/src/zopfli/deflate.c index 4d124f45..0356eb88 100644 --- a/src/zopfli/deflate.c +++ b/src/zopfli/deflate.c @@ -302,6 +302,9 @@ static void AddLZ77Data(const ZopfliLZ77Store* lz77, unsigned char** out, size_t* outsize) { size_t testlength = 0; size_t i; +#ifdef NDEBUG + (void)expected_data_size; +#endif for (i = lstart; i < lend; i++) { unsigned dist = lz77->dists[i]; diff --git a/src/zopfli/lz77.c b/src/zopfli/lz77.c index 5b8ee19d..f05152fd 100644 --- a/src/zopfli/lz77.c +++ b/src/zopfli/lz77.c @@ -269,10 +269,10 @@ static int GetLengthScore(int length, int distance) { return distance > 1024 ? length - 1 : length; } +#ifndef NDEBUG void ZopfliVerifyLenDist(const unsigned char* data, size_t datasize, size_t pos, unsigned short dist, unsigned short length) { - /* TODO(lode): make this only run in a debug compile, it's for assert only. */ size_t i; assert(pos + length <= datasize); @@ -283,6 +283,7 @@ void ZopfliVerifyLenDist(const unsigned char* data, size_t datasize, size_t pos, } } } +#endif /* Finds how long the match of scan and match is. Can be used to find how many @@ -422,7 +423,9 @@ void ZopfliFindLongestMatch(ZopfliBlockState* s, const ZopfliHash* h, int* hhead = h->head; unsigned short* hprev = h->prev; +#ifndef NDEBUG int* hhashval = h->hashval; +#endif int hval = h->val; #ifdef ZOPFLI_LONGEST_MATCH_CACHE @@ -512,7 +515,9 @@ void ZopfliFindLongestMatch(ZopfliBlockState* s, const ZopfliHash* h, /* Now use the hash that encodes the length and first byte. */ hhead = h->head2; hprev = h->prev2; +#ifndef NDEBUG hhashval = h->hashval2; +#endif hval = h->val2; } #endif @@ -596,7 +601,9 @@ void ZopfliLZ77Greedy(ZopfliBlockState* s, const unsigned char* in, dist = prev_match; lengthscore = prevlengthscore; /* Add to output. */ +#ifndef NDEBUG ZopfliVerifyLenDist(in, inend, i - 1, dist, leng); +#endif ZopfliStoreLitLenDist(leng, dist, i - 1, store); for (j = 2; j < leng; j++) { assert(i < inend); @@ -617,7 +624,9 @@ void ZopfliLZ77Greedy(ZopfliBlockState* s, const unsigned char* in, /* Add to output. */ if (lengthscore >= ZOPFLI_MIN_MATCH) { +#ifndef NDEBUG ZopfliVerifyLenDist(in, inend, i, dist, leng); +#endif ZopfliStoreLitLenDist(leng, dist, i, store); } else { leng = 1; diff --git a/src/zopfli/lz77.h b/src/zopfli/lz77.h index 2cc98b5d..89c11181 100644 --- a/src/zopfli/lz77.h +++ b/src/zopfli/lz77.h @@ -125,8 +125,10 @@ void ZopfliFindLongestMatch( /* Verifies if length and dist are indeed valid, only used for assertion. */ +#ifndef NDEBUG void ZopfliVerifyLenDist(const unsigned char* data, size_t datasize, size_t pos, unsigned short dist, unsigned short length); +#endif /* Does LZ77 using an algorithm similar to gzip, with lazy matching, rather than diff --git a/src/zopfli/squeeze.c b/src/zopfli/squeeze.c index d4e66af0..98568ba6 100644 --- a/src/zopfli/squeeze.c +++ b/src/zopfli/squeeze.c @@ -372,7 +372,9 @@ static void FollowPath(ZopfliBlockState* s, ZopfliFindLongestMatch(s, h, in, pos, inend, length, 0, &dist, &dummy_length); assert(!(dummy_length != length && length > 2 && dummy_length > 2)); +#ifndef NDEBUG ZopfliVerifyLenDist(in, inend, pos, dist, length); +#endif ZopfliStoreLitLenDist(length, dist, pos, store); total_length_test += length; } else {