From fcae730bf820680460c89e36cc8cfd8c79cc55d3 Mon Sep 17 00:00:00 2001 From: SId Price Date: Sun, 26 Jun 2022 08:50:21 -0600 Subject: [PATCH] Correct scanf format specifier Rather than casting here, use PRIu32 - as in "%" PRIu32 ".%" PRIu32 - it's undefined behaviour and quite illegal to do the cast as, depending on platform, you'll end up with only some of the bytes in units and tenths written and which ones and what that means will depend on endianess. --- src/platforms/hosted/platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/hosted/platform.c b/src/platforms/hosted/platform.c index 67e6931..3766693 100644 --- a/src/platforms/hosted/platform.c +++ b/src/platforms/hosted/platform.c @@ -412,7 +412,7 @@ uint32_t platform_target_voltage_sense(void) uint32_t units = 0, tenths = 0 ; result = remote_target_voltage() ; if (result != NULL) { - sscanf(result,"%u.%u", (unsigned int *) &units, (unsigned int *) &tenths) ; + sscanf(result,"%"PRIu32".%"PRIu32, &units, &tenths) ; targetVoltage = (units * 10) + tenths ; } break ;