Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 116213
b: refs/heads/master
c: 727d2dc
h: refs/heads/master
i:
  116211: 20f3284
v: v3
  • Loading branch information
Adrian Hunter authored and Artem Bityutskiy committed Oct 19, 2008
1 parent d292c12 commit ed895e3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: be2f6bd62d0d4246a9227dacbe2469e1f0eccf26
refs/heads/master: 727d2dc045930b29dc68d56d5032d23661ba8503
45 changes: 38 additions & 7 deletions trunk/fs/ubifs/lpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,25 +288,56 @@ uint32_t ubifs_unpack_bits(uint8_t **addr, int *pos, int nrbits)
const int k = 32 - nrbits;
uint8_t *p = *addr;
int b = *pos;
uint32_t val;
uint32_t uninitialized_var(val);
const int bytes = (nrbits + b + 7) >> 3;

ubifs_assert(nrbits > 0);
ubifs_assert(nrbits <= 32);
ubifs_assert(*pos >= 0);
ubifs_assert(*pos < 8);
if (b) {
val = p[1] | ((uint32_t)p[2] << 8) | ((uint32_t)p[3] << 16) |
((uint32_t)p[4] << 24);
switch (bytes) {
case 2:
val = p[1];
break;
case 3:
val = p[1] | ((uint32_t)p[2] << 8);
break;
case 4:
val = p[1] | ((uint32_t)p[2] << 8) |
((uint32_t)p[3] << 16);
break;
case 5:
val = p[1] | ((uint32_t)p[2] << 8) |
((uint32_t)p[3] << 16) |
((uint32_t)p[4] << 24);
}
val <<= (8 - b);
val |= *p >> b;
nrbits += b;
} else
val = p[0] | ((uint32_t)p[1] << 8) | ((uint32_t)p[2] << 16) |
((uint32_t)p[3] << 24);
} else {
switch (bytes) {
case 1:
val = p[0];
break;
case 2:
val = p[0] | ((uint32_t)p[1] << 8);
break;
case 3:
val = p[0] | ((uint32_t)p[1] << 8) |
((uint32_t)p[2] << 16);
break;
case 4:
val = p[0] | ((uint32_t)p[1] << 8) |
((uint32_t)p[2] << 16) |
((uint32_t)p[3] << 24);
break;
}
}
val <<= k;
val >>= k;
b = nrbits & 7;
p += nrbits / 8;
p += nrbits >> 3;
*addr = p;
*pos = b;
ubifs_assert((val >> nrbits) == 0 || nrbits - b == 32);
Expand Down

0 comments on commit ed895e3

Please sign in to comment.