diff options
author | Julius Werner <jwerner@chromium.org> | 2017-11-03 13:54:16 -0700 |
---|---|---|
committer | Julius Werner <jwerner@chromium.org> | 2017-11-06 20:46:37 +0000 |
commit | 59e9080dcb136e2f4227a65140010aa442206dda (patch) | |
tree | 68bbac9d6d8a411150a29c6070844f52e4ea0eee | |
parent | b202a01acd9617a37ed465a9b759128683d1fdf0 (diff) |
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>
-rw-r--r-- | payloads/libpayload/include/endian.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/payloads/libpayload/include/endian.h b/payloads/libpayload/include/endian.h index 2655634c93..2dcfa1f8da 100644 --- a/payloads/libpayload/include/endian.h +++ b/payloads/libpayload/include/endian.h @@ -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) |