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.
This commit is contained in:
SId Price 2022-06-26 08:50:21 -06:00 committed by Rachel Mant
parent 02d2ba98d5
commit fcae730bf8
1 changed files with 1 additions and 1 deletions

View File

@ -412,7 +412,7 @@ uint32_t platform_target_voltage_sense(void)
uint32_t units = 0, tenths = 0 ; uint32_t units = 0, tenths = 0 ;
result = remote_target_voltage() ; result = remote_target_voltage() ;
if (result != NULL) { if (result != NULL) {
sscanf(result,"%u.%u", (unsigned int *) &units, (unsigned int *) &tenths) ; sscanf(result,"%"PRIu32".%"PRIu32, &units, &tenths) ;
targetVoltage = (units * 10) + tenths ; targetVoltage = (units * 10) + tenths ;
} }
break ; break ;