From 4c5fdf8cf425b9676a01cc36fbfd5cd9b3abc4a6 Mon Sep 17 00:00:00 2001 From: John Robertson Date: Sun, 15 Jan 2023 12:41:48 +0000 Subject: [PATCH] Fix char arrayy too small issue cValue array is not large enough to include a string terminator IF nValueChars is larger than dec 9. The next itoa function will write a string terminator over the end of the array corrupting whatever is there in memory. --- src/elm327/PidProcessor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/elm327/PidProcessor.cpp b/src/elm327/PidProcessor.cpp index e4fdc59..ed1413d 100644 --- a/src/elm327/PidProcessor.cpp +++ b/src/elm327/PidProcessor.cpp @@ -126,7 +126,7 @@ uint32_t PidProcessor:: getSupportedPids(uint8_t pid) { void PidProcessor::getFormattedResponse(char *response, uint8_t totalNumberOfChars, String pid, uint32_t value) { uint8_t nValueChars = totalNumberOfChars - PID_N_BYTES * N_CHARS_IN_BYTE; - char cValue[2]; + char cValue[2 + 1]; itoa(nValueChars, cValue, DEC); String mask = "%s%0"; mask.concat(cValue);