getPinNameByAdcChannel: be more safe
Know buffer size Use snprintf Expect null from portname()
This commit is contained in:
parent
4007e0d7f8
commit
42213ac172
|
@ -237,16 +237,16 @@ void initPeriodicEvents() {
|
|||
fastController.start();
|
||||
}
|
||||
|
||||
char * getPinNameByAdcChannel(const char *msg, adc_channel_e hwChannel, char *buffer) {
|
||||
char * getPinNameByAdcChannel(const char *msg, adc_channel_e hwChannel, char *buffer, size_t bufferSize) {
|
||||
#if HAL_USE_ADC
|
||||
if (!isAdcChannelValid(hwChannel)) {
|
||||
strcpy(buffer, "NONE");
|
||||
snprintf(buffer, bufferSize, "NONE");
|
||||
} else {
|
||||
strcpy(buffer, portname(getAdcChannelPort(msg, hwChannel)));
|
||||
itoa10(&buffer[2], getAdcChannelPin(hwChannel));
|
||||
const char *name = portname(getAdcChannelPort(msg, hwChannel));
|
||||
snprintf(buffer, bufferSize, "%s%d", name ? name : "null", getAdcChannelPin(hwChannel));
|
||||
}
|
||||
#else
|
||||
strcpy(buffer, "NONE");
|
||||
snprintf(buffer, bufferSize, "NONE");
|
||||
#endif /* HAL_USE_ADC */
|
||||
return buffer;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#define SLOW_CALLBACK_PERIOD_MS 50
|
||||
|
||||
bool validateConfigOnStartUpOrBurn();
|
||||
char * getPinNameByAdcChannel(const char *msg, adc_channel_e hwChannel, char *buffer);
|
||||
char * getPinNameByAdcChannel(const char *msg, adc_channel_e hwChannel, char *buffer, size_t bufferSize);
|
||||
void initPeriodicEvents();
|
||||
// see also applyNewHardwareSettings
|
||||
void initRealHardwareEngineController();
|
||||
|
|
|
@ -39,7 +39,7 @@ static void printMAPInfo() {
|
|||
char pinNameBuffer[16];
|
||||
|
||||
efiPrintf("MAP %.2fv @%s", getVoltage("mapinfo", mapAdc),
|
||||
getPinNameByAdcChannel("map", mapAdc, pinNameBuffer));
|
||||
getPinNameByAdcChannel("map", mapAdc, pinNameBuffer, sizeof(pinNameBuffer)));
|
||||
if (engineConfiguration->map.sensor.type == MT_CUSTOM) {
|
||||
efiPrintf("at %.2fv=%.2f at %.2fv=%.2f",
|
||||
engineConfiguration->mapLowValueVoltage,
|
||||
|
|
|
@ -183,7 +183,7 @@ static void printTpsSenser(const char *msg, SensorType sensor, int16_t min, int1
|
|||
char pinNameBuffer[16];
|
||||
|
||||
efiPrintf("tps min (closed) %d/max (full) %d v=%.2f @%s", min, max,
|
||||
raw, getPinNameByAdcChannel(msg, channel, pinNameBuffer));
|
||||
raw, getPinNameByAdcChannel(msg, channel, pinNameBuffer, sizeof(pinNameBuffer)));
|
||||
|
||||
|
||||
efiPrintf("current 10bit=%d value=%.2f", convertVoltageTo10bitADC(raw), tps.value_or(0));
|
||||
|
|
|
@ -187,7 +187,7 @@ void AdcSubscription::PrintInfo() {
|
|||
name,
|
||||
channel,
|
||||
getAdcMode(channel),
|
||||
getPinNameByAdcChannel(name, channel, pinNameBuffer),
|
||||
getPinNameByAdcChannel(name, channel, pinNameBuffer, sizeof(pinNameBuffer)),
|
||||
mcuVolts, sensorVolts, entry.VoltsPerAdcVolt
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue