Fix SetStatusDelimiter: stack over-read and pointer-sign warnings

Two remaining issues in YEEP144_BluetoothUART.c, neither addressed by 1.2.

SetStatusDelimiter() transmits sizeof(rxBuf) = 10 bytes from an 8-byte stack
buffer (rxBuf is a different buffer declared earlier in the same function), so
two bytes of stack garbage follow every "SO" command the module receives. Send
strlen(txBuf) instead.

The same function passes char* to HAL_UART_Transmit(), which takes
const uint8_t*, producing three -Wpointer-sign warnings. They sit on the same
lines as the over-read, which is part of why it went unnoticed; with the casts
the file compiles warning-free.

See CODE_FIXES.md for the full write-up.
This commit is contained in:
2026-10-28 14:37:51 +00:00
parent 50e4ba8a07
commit ee18d27722
2 changed files with 115 additions and 3 deletions

View File

@@ -192,7 +192,7 @@ void YEEP144_BluetoothUART_SetStatusDelimiter(char prefix, char postfix){
uint16_t rxSize;
// Enter command mode
HAL_UART_Transmit(&huart2, "$$$", 3, UART_POLL_TIMEOUT);
HAL_UART_Transmit(&huart2, (const uint8_t *)"$$$", 3, UART_POLL_TIMEOUT);
// Wait to receive data back from BT module
HAL_UARTEx_ReceiveToIdle(&huart2, rxBuf, 10, &rxSize, UART_POLL_TIMEOUT);
@@ -211,13 +211,17 @@ void YEEP144_BluetoothUART_SetStatusDelimiter(char prefix, char postfix){
else{
sprintf(txBuf, "SO,%c,%c%c", prefix, postfix, '\r');
}
HAL_UART_Transmit(&huart2, txBuf, sizeof(rxBuf), UART_POLL_TIMEOUT);
// rxBuf is a different, unrelated buffer (uint8_t rxBuf[10]); using its
// size here transmits 10 bytes from this 8-byte array, so two bytes of
// stack garbage follow every command. Send exactly the string.
HAL_UART_Transmit(&huart2, (const uint8_t *)txBuf, (uint16_t)strlen(txBuf),
UART_POLL_TIMEOUT);
// Wait to receive data back from BT module
HAL_UARTEx_ReceiveToIdle(&huart2, rxBuf, 10, &rxSize, UART_POLL_TIMEOUT);
// Reboot device to make changes
HAL_UART_Transmit(&huart2, "R,1", 3, UART_POLL_TIMEOUT);
HAL_UART_Transmit(&huart2, (const uint8_t *)"R,1", 3, UART_POLL_TIMEOUT);
// Wait to receive data back from BT module
HAL_UARTEx_ReceiveToIdle(&huart2, rxBuf, 10, &rxSize, UART_POLL_TIMEOUT);