endian: Fix bebitenc() to actually encode big-endian

bebitenc() just runs a downward loop over the same body as lebitenc().
That doesn't give you a byte-swapped result, it gives you the same final
value, just starting from the other side to fill it in. (Also, it
confused i++ and i--, so it really gives you a compiler error.)

The correct code needs to have the array index inverted relative to the
bit shift index to produce a big endian result.

Change-Id: I5c2da3a196334844ce23468bd0124bbe2f378c46
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://review.coreboot.org/22322
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
Julius Werner 2017-11-03 13:54:16 -07:00
parent b202a01acd
commit 59e9080dcb
1 changed files with 2 additions and 2 deletions

View File

@ -132,8 +132,8 @@ static inline void bebitenc(void *pp, uint32_t u, uint8_t b)
uint8_t *p = (uint8_t *)pp;
int i;
for (i = (b - 1); i >= 0; i++)
p[i] = (u >> i*8) & 0xFF;
for (i = 0; i < b; i++)
p[(b - 1) - i] = (u >> i*8) & 0xFF;
}
static inline void be16enc(void *pp, uint16_t u)