=========================================================================== * Fill the window when the lookahead becomes insufficient. * Updates strstart and lookahead. * * IN assertion: lookahead < MIN_LOOKAHEAD * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD * At least one byte has been read, or avail_in == 0; reads are * performed for at least two bytes (required for the zi
(s)
| 1595 | * option -- not supported here). |
| 1596 | */ |
| 1597 | local void fill_window(s) |
| 1598 | |
| 1599 | deflate_state* s; |
| 1600 | { |
| 1601 | unsigned n; |
| 1602 | unsigned more; /* Amount of free space at the end of the window. */ |
| 1603 | uInt wsize = s->w_size; |
| 1604 | |
| 1605 | Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); |
| 1606 | |
| 1607 | do |
| 1608 | { |
| 1609 | more = (unsigned)(s->window_size - (ulg)s->lookahead - (ulg)s->strstart); |
| 1610 | |
| 1611 | /* Deal with !@#$% 64K limit: */ |
| 1612 | if (sizeof(int) <= 2) |
| 1613 | { |
| 1614 | if (more == 0 && s->strstart == 0 && s->lookahead == 0) |
| 1615 | { |
| 1616 | more = wsize; |
| 1617 | } |
| 1618 | else if (more == (unsigned)(-1)) |
| 1619 | { |
| 1620 | /* Very unlikely, but possible on 16 bit machine if |
| 1621 | * strstart == 0 && lookahead == 1 (input done a byte at time) |
| 1622 | */ |
| 1623 | more--; |
| 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | /* If the window is almost full and there is insufficient lookahead, |
| 1628 | * move the upper half to the lower one to make room in the upper half. |
| 1629 | */ |
| 1630 | if (s->strstart >= wsize + MAX_DIST(s)) |
| 1631 | { |
| 1632 | zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more); |
| 1633 | s->match_start -= wsize; |
| 1634 | s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ |
| 1635 | s->block_start -= (long)wsize; |
| 1636 | slide_hash(s); |
| 1637 | more += wsize; |
| 1638 | } |
| 1639 | if (s->strm->avail_in == 0) break; |
| 1640 | |
| 1641 | /* If there was no sliding: |
| 1642 | * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && |
| 1643 | * more == window_size - lookahead - strstart |
| 1644 | * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) |
| 1645 | * => more >= window_size - 2*WSIZE + 2 |
| 1646 | * In the BIG_MEM or MMAP case (not yet supported), |
| 1647 | * window_size == input_size + MIN_LOOKAHEAD && |
| 1648 | * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. |
| 1649 | * Otherwise, window_size == 2*WSIZE so more >= 2. |
| 1650 | * If there was sliding, more >= WSIZE. So in all cases, more >= 2. |
| 1651 | */ |
| 1652 | Assert(more >= 2, "more < 2"); |
| 1653 | |
| 1654 | n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); |
no test coverage detected