1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Add some assertions in sshzlib.c.

gcc 4.8 compiling with -O3 gives a new warning about the access to
st->pending at the top of lz77_compress, because for some reason it
thinks there's an out-of-bounds array access there (or perhaps just a
potential one, I'm not really sure which side -Warray-bounds is erring
on). Add an assertion reassuring it that st->npending can't get bigger
than the size of st->pending at the site it's complaining about, and a
second one at the site where st->npending is increased (just in case
my analysis of why it can't happen was wrong!). Also add a comment
explaining the assertions.

[originally from svn r10144]
This commit is contained in:
Simon Tatham 2014-02-22 18:02:14 +00:00
parent 3e71e3f9c0
commit e2a5c6b679

View File

@ -205,9 +205,16 @@ static void lz77_compress(struct LZ77Context *ctx,
struct Match defermatch, matches[MAXMATCH];
int deferchr;
assert(st->npending <= HASHCHARS);
/*
* Add any pending characters from last time to the window. (We
* might not be able to.)
*
* This leaves st->pending empty in the usual case (when len >=
* HASHCHARS); otherwise it leaves st->pending empty enough that
* adding all the remaining 'len' characters will not push it past
* HASHCHARS in size.
*/
for (i = 0; i < st->npending; i++) {
unsigned char foo[HASHCHARS];
@ -334,6 +341,7 @@ static void lz77_compress(struct LZ77Context *ctx,
if (len >= HASHCHARS) {
lz77_advance(st, *data, lz77_hash(data));
} else {
assert(st->npending < HASHCHARS);
st->pending[st->npending++] = *data;
}
data++;