static unsigned long get_hdr_size(const unsigned char **datap)
{
const unsigned char *data = *datap;
- unsigned long size;
- unsigned char cmd;
- int i;
- size = i = 0;
- cmd = *data++;
- while (cmd) {
- if (cmd & 1)
- size |= *data++ << i;
- i += 8;
- cmd >>= 1;
+ unsigned char cmd = *data++;
+ unsigned long size = cmd & ~0x80;
+ int i = 7;
+ while (cmd & 0x80) {
+ cmd = *data++;
+ size |= (cmd & ~0x80) << i;
+ i += 7;
}
*datap = data;
return size;
unsigned char cmd;
unsigned long src_size, dst_size, out;
- /* the smallest delta size possible is 6 bytes */
- if (delta_size < 6)
+ /* the smallest delta size possible is 4 bytes */
+ if (delta_size < 4)
return -1;
data = delta_buf;
top = to_buf + to_size;
/* store reference buffer size */
- orig = out + outpos++;
- *orig = i = 0;
- do {
- if (from_size & 0xff) {
- *orig |= (1 << i);
- out[outpos++] = from_size;
- }
- i++;
- from_size >>= 8;
- } while (from_size);
+ out[outpos++] = from_size;
+ from_size >>= 7;
+ while (from_size) {
+ out[outpos - 1] |= 0x80;
+ out[outpos++] = from_size;
+ from_size >>= 7;
+ }
/* store target buffer size */
- orig = out + outpos++;
- *orig = i = 0;
- do {
- if (to_size & 0xff) {
- *orig |= (1 << i);
- out[outpos++] = to_size;
- }
- i++;
- to_size >>= 8;
- } while (to_size);
+ out[outpos++] = to_size;
+ to_size >>= 7;
+ while (to_size) {
+ out[outpos - 1] |= 0x80;
+ out[outpos++] = to_size;
+ to_size >>= 7;
+ }
inscnt = 0;
moff = 0;
unsigned long size;
int i;
- /* the smallest delta size possible is 6 bytes */
- if (delta_size < 6)
+ /* the smallest delta size possible is 4 bytes */
+ if (delta_size < 4)
return NULL;
data = delta_buf;
top = delta_buf + delta_size;
/* make sure the orig file size matches what we expect */
- size = i = 0;
cmd = *data++;
- while (cmd) {
- if (cmd & 1)
- size |= *data++ << i;
- i += 8;
- cmd >>= 1;
+ size = cmd & ~0x80;
+ i = 7;
+ while (cmd & 0x80) {
+ cmd = *data++;
+ size |= (cmd & ~0x80) << i;
+ i += 7;
}
if (size != src_size)
return NULL;
/* now the result size */
- size = i = 0;
cmd = *data++;
- while (cmd) {
- if (cmd & 1)
- size |= *data++ << i;
- i += 8;
- cmd >>= 1;
+ size = cmd & ~0x80;
+ i = 7;
+ while (cmd & 0x80) {
+ cmd = *data++;
+ size |= (cmd & ~0x80) << i;
+ i += 7;
}
dst_buf = malloc(size);
if (!dst_buf)