From 0bb7050c608bb38b2f4db2cae2c8f4a93de54e28 Mon Sep 17 00:00:00 2001 From: Matthias Kolja Miehl Date: Sun, 21 Aug 2016 02:28:31 +0200 Subject: [PATCH] cpu/stm32f3: uart: make sure that 'port' and 'dev' are !=NULL This fixes some cppcheck nullPointer errors. --- cpu/stm32f3/periph/uart.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cpu/stm32f3/periph/uart.c b/cpu/stm32f3/periph/uart.c index cd1a864d8b..d8f8473d18 100644 --- a/cpu/stm32f3/periph/uart.c +++ b/cpu/stm32f3/periph/uart.c @@ -119,6 +119,12 @@ static int init_base(uart_t uart, uint32_t baudrate) return -1; } + /* Make sure port and dev are != NULL here, i.e. that the variables are + * assigned in all non-returning branches of the switch at the top of this + * function. */ + assert(port != NULL); + assert(dev != NULL); + /* uart_configure RX and TX pins, set pin to use alternative function mode */ port->MODER &= ~(3 << (rx_pin * 2) | 3 << (tx_pin * 2)); port->MODER |= 2 << (rx_pin * 2) | 2 << (tx_pin * 2); @@ -178,6 +184,10 @@ void uart_write(uart_t uart, const uint8_t *data, size_t len) return; } + /* Make sure dev is != NULL here, i.e. that the variable is assigned in + * all non-returning branches of the switch at the top of this function. */ + assert(dev != NULL); + for (size_t i = 0; i < len; i++) { while (!(dev->ISR & USART_ISR_TXE)) {} dev->TDR = data[i];