Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect NDEBUG flag #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/zopfli/deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
11 changes: 10 additions & 1 deletion src/zopfli/lz77.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/zopfli/lz77.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/zopfli/squeeze.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down