diff --git a/boot/zcbor/include/zcbor_print.h b/boot/zcbor/include/zcbor_print.h index 22a5637d3..ef3bc1d73 100644 --- a/boot/zcbor/include/zcbor_print.h +++ b/boot/zcbor/include/zcbor_print.h @@ -73,17 +73,17 @@ do { \ #endif __attribute__((used)) -static void zcbor_print_compare_lines(const uint8_t *str1, const uint8_t *str2, uint32_t size) +static void zcbor_print_compare_lines(const uint8_t *str1, const uint8_t *str2, size_t size) { - for (uint32_t j = 0; j < size; j++) { + for (size_t j = 0; j < size; j++) { zcbor_do_print("%x ", str1[j]); } zcbor_do_print("\r\n"); - for (uint32_t j = 0; j < size; j++) { + for (size_t j = 0; j < size; j++) { zcbor_do_print("%x ", str2[j]); } zcbor_do_print("\r\n"); - for (uint32_t j = 0; j < size; j++) { + for (size_t j = 0; j < size; j++) { zcbor_do_print("%x ", str1[j] != str2[j]); } zcbor_do_print("\r\n"); @@ -91,10 +91,10 @@ static void zcbor_print_compare_lines(const uint8_t *str1, const uint8_t *str2, } __attribute__((used)) -static void zcbor_print_compare_strings(const uint8_t *str1, const uint8_t *str2, uint32_t size) +static void zcbor_print_compare_strings(const uint8_t *str1, const uint8_t *str2, size_t size) { - for (uint32_t i = 0; i <= size / 16; i++) { - zcbor_do_print("line %d (char %d)\r\n", i, i*16); + for (size_t i = 0; i <= size / 16; i++) { + zcbor_do_print("line %zu (char %zu)\r\n", i, i*16); zcbor_print_compare_lines(&str1[i*16], &str2[i*16], MIN(16, (size - i*16))); } @@ -102,12 +102,12 @@ static void zcbor_print_compare_strings(const uint8_t *str1, const uint8_t *str2 } __attribute__((used)) -static void zcbor_print_compare_strings_diff(const uint8_t *str1, const uint8_t *str2, uint32_t size) +static void zcbor_print_compare_strings_diff(const uint8_t *str1, const uint8_t *str2, size_t size) { bool printed = false; - for (uint32_t i = 0; i <= size / 16; i++) { + for (size_t i = 0; i <= size / 16; i++) { if (memcmp(&str1[i*16], &str2[i*16], MIN(16, (size - i*16))) != 0) { - zcbor_do_print("line %d (char %d)\r\n", i, i*16); + zcbor_do_print("line %zu (char %zu)\r\n", i, i*16); zcbor_print_compare_lines(&str1[i*16], &str2[i*16], MIN(16, (size - i*16))); printed = true; diff --git a/boot/zcbor/src/zcbor_common.c b/boot/zcbor/src/zcbor_common.c index f1a039e52..a7c9ee7be 100644 --- a/boot/zcbor/src/zcbor_common.c +++ b/boot/zcbor/src/zcbor_common.c @@ -355,14 +355,19 @@ float zcbor_float16_to_32(uint16_t input) : (expo + (F32_BIAS - F16_BIAS)); uint32_t value32 = (sign << F32_SIGN_OFFS) | (new_expo << F32_EXPO_OFFS) | (mantissa << (F32_EXPO_OFFS - F16_EXPO_OFFS)); - return *(float *)&value32; + float result; + + memcpy(&result, &value32, sizeof(result)); + return result; } } uint16_t zcbor_float32_to_16(float input) { - uint32_t value32 = *(uint32_t *)&input; + uint32_t value32; + + memcpy(&value32, &input, sizeof(value32)); uint32_t sign = value32 >> F32_SIGN_OFFS; uint32_t expo = (value32 >> F32_EXPO_OFFS) & F32_EXPO_MSK; @@ -370,8 +375,10 @@ uint16_t zcbor_float32_to_16(float input) uint16_t value16 = (uint16_t)(sign << F16_SIGN_OFFS); + uint32_t abs_value32 = value32 & ~(1 << F32_SIGN_OFFS); float abs_input; - *(uint32_t *)&abs_input = value32 & ~(1 << F32_SIGN_OFFS); + + memcpy(&abs_input, &abs_value32, sizeof(abs_input)); if (abs_input <= (F16_MIN / 2)) { /* 0 or too small for float16. Round down to 0. value16 is already correct. */