=========================================================================== * 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)
| 1483 | * option -- not supported here). |
| 1484 | */ |
| 1485 | local void fill_window(s) |
| 1486 | deflate_state *s; |
| 1487 | { |
| 1488 | unsigned n; |
| 1489 | unsigned more; /* Amount of free space at the end of the window. */ |
| 1490 | uInt wsize = s->w_size; |
| 1491 | |
| 1492 | Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); |
| 1493 | |
| 1494 | do { |
| 1495 | more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); |
| 1496 | |
| 1497 | /* Deal with !@#$% 64K limit: */ |
| 1498 | if (sizeof(int) <= 2) { |
| 1499 | if (more == 0 && s->strstart == 0 && s->lookahead == 0) { |
| 1500 | more = wsize; |
| 1501 | |
| 1502 | } else if (more == (unsigned)(-1)) { |
| 1503 | /* Very unlikely, but possible on 16 bit machine if |
| 1504 | * strstart == 0 && lookahead == 1 (input done a byte at time) |
| 1505 | */ |
| 1506 | more--; |
| 1507 | } |
| 1508 | } |
| 1509 | |
| 1510 | /* If the window is almost full and there is insufficient lookahead, |
| 1511 | * move the upper half to the lower one to make room in the upper half. |
| 1512 | */ |
| 1513 | if (s->strstart >= wsize+MAX_DIST(s)) { |
| 1514 | |
| 1515 | zmemcpy(s->window, s->window+wsize, (unsigned)wsize - more); |
| 1516 | s->match_start -= wsize; |
| 1517 | s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ |
| 1518 | s->block_start -= (long) wsize; |
| 1519 | slide_hash(s); |
| 1520 | more += wsize; |
| 1521 | } |
| 1522 | if (s->strm->avail_in == 0) break; |
| 1523 | |
| 1524 | /* If there was no sliding: |
| 1525 | * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && |
| 1526 | * more == window_size - lookahead - strstart |
| 1527 | * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) |
| 1528 | * => more >= window_size - 2*WSIZE + 2 |
| 1529 | * In the BIG_MEM or MMAP case (not yet supported), |
| 1530 | * window_size == input_size + MIN_LOOKAHEAD && |
| 1531 | * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. |
| 1532 | * Otherwise, window_size == 2*WSIZE so more >= 2. |
| 1533 | * If there was sliding, more >= WSIZE. So in all cases, more >= 2. |
| 1534 | */ |
| 1535 | Assert(more >= 2, "more < 2"); |
| 1536 | |
| 1537 | n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); |
| 1538 | s->lookahead += n; |
| 1539 | |
| 1540 | /* Initialize the hash value now that we have some input: */ |
| 1541 | if (s->lookahead + s->insert >= MIN_MATCH) { |
| 1542 | uInt str = s->strstart - s->insert; |
no test coverage detected