@@ -483,18 +483,21 @@ private bool FindLongestMatch(int curMatch)
483483 int niceLength = Math . Min ( this . niceLength , this . lookahead ) ;
484484
485485 int matchStrt = this . matchStart ;
486- this . matchLen = Math . Max ( this . matchLen , DeflaterConstants . MIN_MATCH - 1 ) ;
487486 int matchLength = this . matchLen ;
487+ matchLength = Math . Max ( matchLength , DeflaterConstants . MIN_MATCH - 1 ) ;
488+ this . matchLen = matchLength ;
488489
489- if ( scan + matchLength > scanMax )
490+ if ( scan > scanMax - matchLength )
490491 {
491492 return false ;
492493 }
493494
495+ int scanEndPosition = scan + matchLength ;
496+
494497 byte * pinnedWindow = this . pinnedWindowPointer ;
495498 int scanStart = this . strstart ;
496- byte scanEnd1 = pinnedWindow [ scan + matchLength - 1 ] ;
497- byte scanEnd = pinnedWindow [ scan + matchLength ] ;
499+ byte scanEnd1 = pinnedWindow [ scanEndPosition - 1 ] ;
500+ byte scanEnd = pinnedWindow [ scanEndPosition ] ;
498501
499502 // Do not waste too much time if we already have a good match:
500503 if ( matchLength >= this . goodLength )
@@ -508,8 +511,9 @@ private bool FindLongestMatch(int curMatch)
508511 match = curMatch ;
509512 scan = scanStart ;
510513
511- if ( pinnedWindow [ match + matchLength ] != scanEnd
512- || pinnedWindow [ match + matchLength - 1 ] != scanEnd1
514+ int matchEndPosition = match + matchLength ;
515+ if ( pinnedWindow [ matchEndPosition ] != scanEnd
516+ || pinnedWindow [ matchEndPosition - 1 ] != scanEnd1
513517 || pinnedWindow [ match ] != pinnedWindow [ scan ]
514518 || pinnedWindow [ ++ match ] != pinnedWindow [ ++ scan ] )
515519 {
@@ -685,6 +689,7 @@ private bool DeflateFast(bool flush, bool finish)
685689 return false ;
686690 }
687691
692+ const int windowLen = ( 2 * DeflaterConstants . WSIZE ) - DeflaterConstants . MIN_LOOKAHEAD ;
688693 while ( this . lookahead >= DeflaterConstants . MIN_LOOKAHEAD || flush )
689694 {
690695 if ( this . lookahead == 0 )
@@ -695,7 +700,7 @@ private bool DeflateFast(bool flush, bool finish)
695700 return false ;
696701 }
697702
698- if ( this . strstart > ( 2 * DeflaterConstants . WSIZE ) - DeflaterConstants . MIN_LOOKAHEAD )
703+ if ( this . strstart > windowLen )
699704 {
700705 // slide window, as FindLongestMatch needs this.
701706 // This should only happen when flushing and the window
@@ -766,6 +771,7 @@ private bool DeflateSlow(bool flush, bool finish)
766771 return false ;
767772 }
768773
774+ const int windowLen = ( 2 * DeflaterConstants . WSIZE ) - DeflaterConstants . MIN_LOOKAHEAD ;
769775 while ( this . lookahead >= DeflaterConstants . MIN_LOOKAHEAD || flush )
770776 {
771777 if ( this . lookahead == 0 )
@@ -783,7 +789,7 @@ private bool DeflateSlow(bool flush, bool finish)
783789 return false ;
784790 }
785791
786- if ( this . strstart >= ( 2 * DeflaterConstants . WSIZE ) - DeflaterConstants . MIN_LOOKAHEAD )
792+ if ( this . strstart >= windowLen )
787793 {
788794 // slide window, as FindLongestMatch needs this.
789795 // This should only happen when flushing and the window
0 commit comments