PATCH: Fix non-aligned offset miscalculation and use len as left bytes to decode instead of address comparasions

This commit is contained in:
Alex D. 2021-11-14 13:20:31 +00:00
parent 94892fa5dd
commit cc742932a2
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
1 changed files with 6 additions and 6 deletions

View File

@ -114,17 +114,17 @@ corelibs_baseven_decode (const uint8_t *src, size_t len, uint8_t *dest, size_t m
if (corelibs_baseven_size_decoded (len) > max) err = CORELIBS_BASEVEN_ERR_MEM_OVERFLOW;
if (!err) {
const uint8_t *const end = src + len;
while (1) {
const uint8_t con = (src + DECODED < end) ? DECODED : (uint8_t) (end - src); // Count of bytes to the extra post-encoding byte
const uint8_t con = ((ENCODED - 1) < len) ? (ENCODED - 1) : (uint8_t) len - 1; // Count of bytes to the extra post-encoding byte as OFFSET (8 -> 7)
for (uint8_t p = 0; p < con; p++) {
dest[p] = (uint8_t) ((corelibs_baseven_bits_nth (src[con], p + 1) << DECODED) // Get n-th bit from last byte and shift it to the beginning
| (src[p] ^ RESERVEDBIT) // Discard reserved bit and merge it with bit from last
dest[p] = (uint8_t) ((corelibs_baseven_bits_nth (src[con], p + 1) << (ENCODED - 1)) // Get n-th bit from last byte and shift it to the beginning
| (src[p] ^ RESERVEDBIT) // Discard reserved bit and merge it with bit from last
);
}
if (src + DECODED < end) {
if ((ENCODED - 1) < len) {
dest += con;
len -= con;
src += ENCODED;
} else {
break;