Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/archival/libunarchive/decompress_unlzma.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 983 by niro, Fri Apr 24 18:33:46 2009 UTC revision 984 by niro, Sun May 30 11:32:42 2010 UTC
# Line 8  Line 8 
8   *   *
9   * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.   * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
10   */   */
   
11  #include "libbb.h"  #include "libbb.h"
12  #include "unarchive.h"  #include "unarchive.h"
13    
14  #if ENABLE_FEATURE_LZMA_FAST  #if ENABLE_FEATURE_LZMA_FAST
15  #  define speed_inline ALWAYS_INLINE  #  define speed_inline ALWAYS_INLINE
16    #  define size_inline
17  #else  #else
18  #  define speed_inline  #  define speed_inline
19    #  define size_inline ALWAYS_INLINE
20  #endif  #endif
21    
22    
# Line 44  typedef struct { Line 45  typedef struct {
45  #define RC_MODEL_TOTAL_BITS 11  #define RC_MODEL_TOTAL_BITS 11
46    
47    
48  /* Called twice: once at startup and once in rc_normalize() */  /* Called twice: once at startup (LZMA_FAST only) and once in rc_normalize() */
49  static void rc_read(rc_t *rc)  static size_inline void rc_read(rc_t *rc)
50  {  {
51   int buffer_size = safe_read(rc->fd, RC_BUFFER, RC_BUFFER_SIZE);   int buffer_size = safe_read(rc->fd, RC_BUFFER, RC_BUFFER_SIZE);
52    //TODO: return -1 instead
53    //This will make unlzma delete broken unpacked file on unpack errors
54   if (buffer_size <= 0)   if (buffer_size <= 0)
55   bb_error_msg_and_die("unexpected EOF");   bb_error_msg_and_die("unexpected EOF");
56   rc->ptr = RC_BUFFER;   rc->ptr = RC_BUFFER;
57   rc->buffer_end = RC_BUFFER + buffer_size;   rc->buffer_end = RC_BUFFER + buffer_size;
58  }  }
59    
60    /* Called twice, but one callsite is in speed_inline'd rc_is_bit_1() */
61    static void rc_do_normalize(rc_t *rc)
62    {
63     if (rc->ptr >= rc->buffer_end)
64     rc_read(rc);
65     rc->range <<= 8;
66     rc->code = (rc->code << 8) | *rc->ptr++;
67    }
68    
69  /* Called once */  /* Called once */
70  static rc_t* rc_init(int fd) /*, int buffer_size) */  static ALWAYS_INLINE rc_t* rc_init(int fd) /*, int buffer_size) */
71  {  {
72   int i;   int i;
73   rc_t *rc;   rc_t *rc;
74    
75   rc = xmalloc(sizeof(*rc) + RC_BUFFER_SIZE);   rc = xzalloc(sizeof(*rc) + RC_BUFFER_SIZE);
76    
77   rc->fd = fd;   rc->fd = fd;
78   /* rc->buffer_size = buffer_size; */   /* rc->ptr = rc->buffer_end; */
  rc->buffer_end = RC_BUFFER + RC_BUFFER_SIZE;  
  rc->ptr = rc->buffer_end;  
79    
  rc->code = 0;  
  rc->range = 0xFFFFFFFF;  
80   for (i = 0; i < 5; i++) {   for (i = 0; i < 5; i++) {
81    #if ENABLE_FEATURE_LZMA_FAST
82   if (rc->ptr >= rc->buffer_end)   if (rc->ptr >= rc->buffer_end)
83   rc_read(rc);   rc_read(rc);
84   rc->code = (rc->code << 8) | *rc->ptr++;   rc->code = (rc->code << 8) | *rc->ptr++;
85    #else
86     rc_do_normalize(rc);
87    #endif
88   }   }
89     rc->range = 0xFFFFFFFF;
90   return rc;   return rc;
91  }  }
92    
# Line 83  static ALWAYS_INLINE void rc_free(rc_t * Line 96  static ALWAYS_INLINE void rc_free(rc_t *
96   free(rc);   free(rc);
97  }  }
98    
 /* Called twice, but one callsite is in speed_inline'd rc_is_bit_0_helper() */  
 static void rc_do_normalize(rc_t *rc)  
 {  
  if (rc->ptr >= rc->buffer_end)  
  rc_read(rc);  
  rc->range <<= 8;  
  rc->code = (rc->code << 8) | *rc->ptr++;  
 }  
99  static ALWAYS_INLINE void rc_normalize(rc_t *rc)  static ALWAYS_INLINE void rc_normalize(rc_t *rc)
100  {  {
101   if (rc->range < (1 << RC_TOP_BITS)) {   if (rc->range < (1 << RC_TOP_BITS)) {
# Line 98  static ALWAYS_INLINE void rc_normalize(r Line 103  static ALWAYS_INLINE void rc_normalize(r
103   }   }
104  }  }
105    
106  /* rc_is_bit_0 is called 9 times */  /* rc_is_bit_1 is called 9 times */
107  /* Why rc_is_bit_0_helper exists?  static speed_inline int rc_is_bit_1(rc_t *rc, uint16_t *p)
  * Because we want to always expose (rc->code < rc->bound) to optimizer.  
  * Thus rc_is_bit_0 is always inlined, and rc_is_bit_0_helper is inlined  
  * only if we compile for speed.  
  */  
 static speed_inline uint32_t rc_is_bit_0_helper(rc_t *rc, uint16_t *p)  
108  {  {
109   rc_normalize(rc);   rc_normalize(rc);
110   rc->bound = *p * (rc->range >> RC_MODEL_TOTAL_BITS);   rc->bound = *p * (rc->range >> RC_MODEL_TOTAL_BITS);
111   return rc->bound;   if (rc->code < rc->bound) {
112  }   rc->range = rc->bound;
113  static ALWAYS_INLINE int rc_is_bit_0(rc_t *rc, uint16_t *p)   *p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS;
114  {   return 0;
115   uint32_t t = rc_is_bit_0_helper(rc, p);   }
  return rc->code < t;  
 }  
   
 /* Called ~10 times, but very small, thus inlined */  
 static speed_inline void rc_update_bit_0(rc_t *rc, uint16_t *p)  
 {  
  rc->range = rc->bound;  
  *p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS;  
 }  
 static speed_inline void rc_update_bit_1(rc_t *rc, uint16_t *p)  
 {  
116   rc->range -= rc->bound;   rc->range -= rc->bound;
117   rc->code -= rc->bound;   rc->code -= rc->bound;
118   *p -= *p >> RC_MOVE_BITS;   *p -= *p >> RC_MOVE_BITS;
119     return 1;
120  }  }
121    
122  /* Called 4 times in unlzma loop */  /* Called 4 times in unlzma loop */
123  static int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)  static speed_inline int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)
124  {  {
125   if (rc_is_bit_0(rc, p)) {   int ret = rc_is_bit_1(rc, p);
126   rc_update_bit_0(rc, p);   *symbol = *symbol * 2 + ret;
127   *symbol *= 2;   return ret;
  return 0;  
  } else {  
  rc_update_bit_1(rc, p);  
  *symbol = *symbol * 2 + 1;  
  return 1;  
  }  
128  }  }
129    
130  /* Called once */  /* Called once */
# Line 172  typedef struct { Line 156  typedef struct {
156   uint8_t pos;   uint8_t pos;
157   uint32_t dict_size;   uint32_t dict_size;
158   uint64_t dst_size;   uint64_t dst_size;
159  } __attribute__ ((packed)) lzma_header_t;  } PACKED lzma_header_t;
160    
161    
162  /* #defines will force compiler to compute/optimize each one with each usage.  /* #defines will force compiler to compute/optimize each one with each usage.
# Line 228  enum { Line 212  enum {
212  };  };
213    
214    
215  USE_DESKTOP(long long) int FAST_FUNC  IF_DESKTOP(long long) int FAST_FUNC
216  unpack_lzma_stream(int src_fd, int dst_fd)  unpack_lzma_stream(int src_fd, int dst_fd)
217  {  {
218   USE_DESKTOP(long long total_written = 0;)   IF_DESKTOP(long long total_written = 0;)
219   lzma_header_t header;   lzma_header_t header;
220   int lc, pb, lp;   int lc, pb, lp;
221   uint32_t pos_state_mask;   uint32_t pos_state_mask;
222   uint32_t literal_pos_mask;   uint32_t literal_pos_mask;
  uint32_t pos;  
223   uint16_t *p;   uint16_t *p;
  uint16_t *prob;  
  uint16_t *prob_lit;  
224   int num_bits;   int num_bits;
225   int num_probs;   int num_probs;
226   rc_t *rc;   rc_t *rc;
227   int i, mi;   int i;
228   uint8_t *buffer;   uint8_t *buffer;
229   uint8_t previous_byte = 0;   uint8_t previous_byte = 0;
230   size_t buffer_pos = 0, global_pos = 0;   size_t buffer_pos = 0, global_pos = 0;
# Line 251  unpack_lzma_stream(int src_fd, int dst_f Line 232  unpack_lzma_stream(int src_fd, int dst_f
232   int state = 0;   int state = 0;
233   uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;   uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
234    
235   xread(src_fd, &header, sizeof(header));   if (full_read(src_fd, &header, sizeof(header)) != sizeof(header)
236     || header.pos >= (9 * 5 * 5)
237     ) {
238     bb_error_msg("bad lzma header");
239     return -1;
240     }
241    
242   if (header.pos >= (9 * 5 * 5))   i = header.pos / 9;
  bb_error_msg_and_die("bad header");  
  mi = header.pos / 9;  
243   lc = header.pos % 9;   lc = header.pos % 9;
244   pb = mi / 5;   pb = i / 5;
245   lp = mi % 5;   lp = i % 5;
246   pos_state_mask = (1 << pb) - 1;   pos_state_mask = (1 << pb) - 1;
247   literal_pos_mask = (1 << lp) - 1;   literal_pos_mask = (1 << lp) - 1;
248    
# Line 266  unpack_lzma_stream(int src_fd, int dst_f Line 250  unpack_lzma_stream(int src_fd, int dst_f
250   header.dst_size = SWAP_LE64(header.dst_size);   header.dst_size = SWAP_LE64(header.dst_size);
251    
252   if (header.dict_size == 0)   if (header.dict_size == 0)
253   header.dict_size = 1;   header.dict_size++;
254    
255   buffer = xmalloc(MIN(header.dst_size, header.dict_size));   buffer = xmalloc(MIN(header.dst_size, header.dict_size));
256    
257   num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));   num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
258   p = xmalloc(num_probs * sizeof(*p));   p = xmalloc(num_probs * sizeof(*p));
259   num_probs = LZMA_LITERAL + (LZMA_LIT_SIZE << (lc + lp));   num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
260   for (i = 0; i < num_probs; i++)   for (i = 0; i < num_probs; i++)
261   p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;   p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
262    
# Line 280  unpack_lzma_stream(int src_fd, int dst_f Line 264  unpack_lzma_stream(int src_fd, int dst_f
264    
265   while (global_pos + buffer_pos < header.dst_size) {   while (global_pos + buffer_pos < header.dst_size) {
266   int pos_state = (buffer_pos + global_pos) & pos_state_mask;   int pos_state = (buffer_pos + global_pos) & pos_state_mask;
267     uint16_t *prob = p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;
268    
269     if (!rc_is_bit_1(rc, prob)) {
270     static const char next_state[LZMA_NUM_STATES] =
271     { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 };
272     int mi = 1;
273    
  prob = p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;  
  if (rc_is_bit_0(rc, prob)) {  
  mi = 1;  
  rc_update_bit_0(rc, prob);  
274   prob = (p + LZMA_LITERAL   prob = (p + LZMA_LITERAL
275          + (LZMA_LIT_SIZE * ((((buffer_pos + global_pos) & literal_pos_mask) << lc)          + (LZMA_LIT_SIZE * ((((buffer_pos + global_pos) & literal_pos_mask) << lc)
276                              + (previous_byte >> (8 - lc))                              + (previous_byte >> (8 - lc))
# Line 294  unpack_lzma_stream(int src_fd, int dst_f Line 280  unpack_lzma_stream(int src_fd, int dst_f
280    
281   if (state >= LZMA_NUM_LIT_STATES) {   if (state >= LZMA_NUM_LIT_STATES) {
282   int match_byte;   int match_byte;
283     uint32_t pos = buffer_pos - rep0;
284    
  pos = buffer_pos - rep0;  
285   while (pos >= header.dict_size)   while (pos >= header.dict_size)
286   pos += header.dict_size;   pos += header.dict_size;
287   match_byte = buffer[pos];   match_byte = buffer[pos];
# Line 304  unpack_lzma_stream(int src_fd, int dst_f Line 290  unpack_lzma_stream(int src_fd, int dst_f
290    
291   match_byte <<= 1;   match_byte <<= 1;
292   bit = match_byte & 0x100;   bit = match_byte & 0x100;
293   prob_lit = prob + 0x100 + bit + mi;   bit ^= (rc_get_bit(rc, prob + 0x100 + bit + mi, &mi) << 8); /* 0x100 or 0 */
  bit ^= (rc_get_bit(rc, prob_lit, &mi) << 8); /* 0x100 or 0 */  
294   if (bit)   if (bit)
295   break;   break;
296   } while (mi < 0x100);   } while (mi < 0x100);
297   }   }
298   while (mi < 0x100) {   while (mi < 0x100) {
299   prob_lit = prob + mi;   rc_get_bit(rc, prob + mi, &mi);
  rc_get_bit(rc, prob_lit, &mi);  
300   }   }
301    
302   state -= 3;   state = next_state[state];
  if (state < 4-3)  
  state = 0;  
  if (state >= 10-3)  
  state -= 6-3;  
303    
304   previous_byte = (uint8_t) mi;   previous_byte = (uint8_t) mi;
305  #if ENABLE_FEATURE_LZMA_FAST  #if ENABLE_FEATURE_LZMA_FAST
# Line 330  unpack_lzma_stream(int src_fd, int dst_f Line 310  unpack_lzma_stream(int src_fd, int dst_f
310   global_pos += header.dict_size;   global_pos += header.dict_size;
311   if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)   if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
312   goto bad;   goto bad;
313   USE_DESKTOP(total_written += header.dict_size;)   IF_DESKTOP(total_written += header.dict_size;)
314   }   }
315  #else  #else
316   len = 1;   len = 1;
# Line 338  unpack_lzma_stream(int src_fd, int dst_f Line 318  unpack_lzma_stream(int src_fd, int dst_f
318  #endif  #endif
319   } else {   } else {
320   int offset;   int offset;
321   uint16_t *prob_len;   uint16_t *prob2;
322    #define prob_len prob2
323    
324   rc_update_bit_1(rc, prob);   prob2 = p + LZMA_IS_REP + state;
325   prob = p + LZMA_IS_REP + state;   if (!rc_is_bit_1(rc, prob2)) {
  if (rc_is_bit_0(rc, prob)) {  
  rc_update_bit_0(rc, prob);  
326   rep3 = rep2;   rep3 = rep2;
327   rep2 = rep1;   rep2 = rep1;
328   rep1 = rep0;   rep1 = rep0;
329   state = state < LZMA_NUM_LIT_STATES ? 0 : 3;   state = state < LZMA_NUM_LIT_STATES ? 0 : 3;
330   prob = p + LZMA_LEN_CODER;   prob2 = p + LZMA_LEN_CODER;
331   } else {   } else {
332   rc_update_bit_1(rc, prob);   prob2 += LZMA_IS_REP_G0 - LZMA_IS_REP;
333   prob = p + LZMA_IS_REP_G0 + state;   if (!rc_is_bit_1(rc, prob2)) {
334   if (rc_is_bit_0(rc, prob)) {   prob2 = (p + LZMA_IS_REP_0_LONG
  rc_update_bit_0(rc, prob);  
  prob = (p + LZMA_IS_REP_0_LONG  
335          + (state << LZMA_NUM_POS_BITS_MAX)          + (state << LZMA_NUM_POS_BITS_MAX)
336          + pos_state          + pos_state
337   );   );
338   if (rc_is_bit_0(rc, prob)) {   if (!rc_is_bit_1(rc, prob2)) {
  rc_update_bit_0(rc, prob);  
   
  state = state < LZMA_NUM_LIT_STATES ? 9 : 11;  
339  #if ENABLE_FEATURE_LZMA_FAST  #if ENABLE_FEATURE_LZMA_FAST
340   pos = buffer_pos - rep0;   uint32_t pos = buffer_pos - rep0;
341     state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
342   while (pos >= header.dict_size)   while (pos >= header.dict_size)
343   pos += header.dict_size;   pos += header.dict_size;
344   previous_byte = buffer[pos];   previous_byte = buffer[pos];
345   goto one_byte1;   goto one_byte1;
346  #else  #else
347     state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
348   len = 1;   len = 1;
349   goto string;   goto string;
350  #endif  #endif
  } else {  
  rc_update_bit_1(rc, prob);  
351   }   }
352   } else {   } else {
353   uint32_t distance;   uint32_t distance;
354    
355   rc_update_bit_1(rc, prob);   prob2 += LZMA_IS_REP_G1 - LZMA_IS_REP_G0;
356   prob = p + LZMA_IS_REP_G1 + state;   distance = rep1;
357   if (rc_is_bit_0(rc, prob)) {   if (rc_is_bit_1(rc, prob2)) {
358   rc_update_bit_0(rc, prob);   prob2 += LZMA_IS_REP_G2 - LZMA_IS_REP_G1;
359   distance = rep1;   distance = rep2;
360   } else {   if (rc_is_bit_1(rc, prob2)) {
  rc_update_bit_1(rc, prob);  
  prob = p + LZMA_IS_REP_G2 + state;  
  if (rc_is_bit_0(rc, prob)) {  
  rc_update_bit_0(rc, prob);  
  distance = rep2;  
  } else {  
  rc_update_bit_1(rc, prob);  
361   distance = rep3;   distance = rep3;
362   rep3 = rep2;   rep3 = rep2;
363   }   }
# Line 400  unpack_lzma_stream(int src_fd, int dst_f Line 367  unpack_lzma_stream(int src_fd, int dst_f
367   rep0 = distance;   rep0 = distance;
368   }   }
369   state = state < LZMA_NUM_LIT_STATES ? 8 : 11;   state = state < LZMA_NUM_LIT_STATES ? 8 : 11;
370   prob = p + LZMA_REP_LEN_CODER;   prob2 = p + LZMA_REP_LEN_CODER;
371   }   }
372    
373   prob_len = prob + LZMA_LEN_CHOICE;   prob_len = prob2 + LZMA_LEN_CHOICE;
374   if (rc_is_bit_0(rc, prob_len)) {   num_bits = LZMA_LEN_NUM_LOW_BITS;
375   rc_update_bit_0(rc, prob_len);   if (!rc_is_bit_1(rc, prob_len)) {
376   prob_len = (prob + LZMA_LEN_LOW   prob_len += LZMA_LEN_LOW - LZMA_LEN_CHOICE
377              + (pos_state << LZMA_LEN_NUM_LOW_BITS));              + (pos_state << LZMA_LEN_NUM_LOW_BITS);
378   offset = 0;   offset = 0;
  num_bits = LZMA_LEN_NUM_LOW_BITS;  
379   } else {   } else {
380   rc_update_bit_1(rc, prob_len);   prob_len += LZMA_LEN_CHOICE_2 - LZMA_LEN_CHOICE;
381   prob_len = prob + LZMA_LEN_CHOICE_2;   if (!rc_is_bit_1(rc, prob_len)) {
382   if (rc_is_bit_0(rc, prob_len)) {   prob_len += LZMA_LEN_MID - LZMA_LEN_CHOICE_2
383   rc_update_bit_0(rc, prob_len);              + (pos_state << LZMA_LEN_NUM_MID_BITS);
  prob_len = (prob + LZMA_LEN_MID  
             + (pos_state << LZMA_LEN_NUM_MID_BITS));  
384   offset = 1 << LZMA_LEN_NUM_LOW_BITS;   offset = 1 << LZMA_LEN_NUM_LOW_BITS;
385   num_bits = LZMA_LEN_NUM_MID_BITS;   num_bits += LZMA_LEN_NUM_MID_BITS - LZMA_LEN_NUM_LOW_BITS;
386   } else {   } else {
387   rc_update_bit_1(rc, prob_len);   prob_len += LZMA_LEN_HIGH - LZMA_LEN_CHOICE_2;
  prob_len = prob + LZMA_LEN_HIGH;  
388   offset = ((1 << LZMA_LEN_NUM_LOW_BITS)   offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
389            + (1 << LZMA_LEN_NUM_MID_BITS));            + (1 << LZMA_LEN_NUM_MID_BITS));
390   num_bits = LZMA_LEN_NUM_HIGH_BITS;   num_bits += LZMA_LEN_NUM_HIGH_BITS - LZMA_LEN_NUM_LOW_BITS;
391   }   }
392   }   }
393   rc_bit_tree_decode(rc, prob_len, num_bits, &len);   rc_bit_tree_decode(rc, prob_len, num_bits, &len);
# Line 432  unpack_lzma_stream(int src_fd, int dst_f Line 395  unpack_lzma_stream(int src_fd, int dst_f
395    
396   if (state < 4) {   if (state < 4) {
397   int pos_slot;   int pos_slot;
398     uint16_t *prob3;
399    
400   state += LZMA_NUM_LIT_STATES;   state += LZMA_NUM_LIT_STATES;
401   prob = p + LZMA_POS_SLOT +   prob3 = p + LZMA_POS_SLOT +
402         ((len < LZMA_NUM_LEN_TO_POS_STATES ? len :         ((len < LZMA_NUM_LEN_TO_POS_STATES ? len :
403           LZMA_NUM_LEN_TO_POS_STATES - 1)           LZMA_NUM_LEN_TO_POS_STATES - 1)
404           << LZMA_NUM_POS_SLOT_BITS);           << LZMA_NUM_POS_SLOT_BITS);
405   rc_bit_tree_decode(rc, prob, LZMA_NUM_POS_SLOT_BITS,   rc_bit_tree_decode(rc, prob3,
406     &pos_slot);   LZMA_NUM_POS_SLOT_BITS, &pos_slot);
407     rep0 = pos_slot;
408   if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {   if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
409   num_bits = (pos_slot >> 1) - 1;   int i2, mi2, num_bits2 = (pos_slot >> 1) - 1;
410   rep0 = 2 | (pos_slot & 1);   rep0 = 2 | (pos_slot & 1);
411   if (pos_slot < LZMA_END_POS_MODEL_INDEX) {   if (pos_slot < LZMA_END_POS_MODEL_INDEX) {
412   rep0 <<= num_bits;   rep0 <<= num_bits2;
413   prob = p + LZMA_SPEC_POS + rep0 - pos_slot - 1;   prob3 = p + LZMA_SPEC_POS + rep0 - pos_slot - 1;
414   } else {   } else {
415   num_bits -= LZMA_NUM_ALIGN_BITS;   for (; num_bits2 != LZMA_NUM_ALIGN_BITS; num_bits2--)
  while (num_bits--)  
416   rep0 = (rep0 << 1) | rc_direct_bit(rc);   rep0 = (rep0 << 1) | rc_direct_bit(rc);
  prob = p + LZMA_ALIGN;  
417   rep0 <<= LZMA_NUM_ALIGN_BITS;   rep0 <<= LZMA_NUM_ALIGN_BITS;
418   num_bits = LZMA_NUM_ALIGN_BITS;   prob3 = p + LZMA_ALIGN;
419   }   }
420   i = 1;   i2 = 1;
421   mi = 1;   mi2 = 1;
422   while (num_bits--) {   while (num_bits2--) {
423   if (rc_get_bit(rc, prob + mi, &mi))   if (rc_get_bit(rc, prob3 + mi2, &mi2))
424   rep0 |= i;   rep0 |= i2;
425   i <<= 1;   i2 <<= 1;
426   }   }
427   } else   }
  rep0 = pos_slot;  
428   if (++rep0 == 0)   if (++rep0 == 0)
429   break;   break;
430   }   }
431    
432   len += LZMA_MATCH_MIN_LEN;   len += LZMA_MATCH_MIN_LEN;
433   SKIP_FEATURE_LZMA_FAST(string:)   IF_NOT_FEATURE_LZMA_FAST(string:)
434   do {   do {
435   pos = buffer_pos - rep0;   uint32_t pos = buffer_pos - rep0;
436   while (pos >= header.dict_size)   while (pos >= header.dict_size)
437   pos += header.dict_size;   pos += header.dict_size;
438   previous_byte = buffer[pos];   previous_byte = buffer[pos];
439   SKIP_FEATURE_LZMA_FAST(one_byte2:)   IF_NOT_FEATURE_LZMA_FAST(one_byte2:)
440   buffer[buffer_pos++] = previous_byte;   buffer[buffer_pos++] = previous_byte;
441   if (buffer_pos == header.dict_size) {   if (buffer_pos == header.dict_size) {
442   buffer_pos = 0;   buffer_pos = 0;
443   global_pos += header.dict_size;   global_pos += header.dict_size;
444   if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)   if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
445   goto bad;   goto bad;
446   USE_DESKTOP(total_written += header.dict_size;)   IF_DESKTOP(total_written += header.dict_size;)
447   }   }
448   len--;   len--;
449   } while (len != 0 && buffer_pos < header.dst_size);   } while (len != 0 && buffer_pos < header.dst_size);
# Line 489  unpack_lzma_stream(int src_fd, int dst_f Line 451  unpack_lzma_stream(int src_fd, int dst_f
451   }   }
452    
453   {   {
454   SKIP_DESKTOP(int total_written = 0; /* success */)   IF_NOT_DESKTOP(int total_written = 0; /* success */)
455   USE_DESKTOP(total_written += buffer_pos;)   IF_DESKTOP(total_written += buffer_pos;)
456   if (full_write(dst_fd, buffer, buffer_pos) != (ssize_t)buffer_pos) {   if (full_write(dst_fd, buffer, buffer_pos) != (ssize_t)buffer_pos) {
457   bad:   bad:
458   total_written = -1; /* failure */   total_written = -1; /* failure */

Legend:
Removed from v.983  
changed lines
  Added in v.984