From 826b34a8ac433e089c8522d949def4d8421ca4a2 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 18 Oct 2021 00:13:40 +0700 Subject: [PATCH] enable -Wnull-dereference --- examples/make.mk | 3 ++- hw/bsp/samg55xplained/board.mk | 2 +- src/portable/nuvoton/nuc505/dcd_nuc505.c | 7 ++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/make.mk b/examples/make.mk index 774625577..793c40aa2 100644 --- a/examples/make.mk +++ b/examples/make.mk @@ -105,7 +105,8 @@ CFLAGS += \ -Wunreachable-code \ -Wcast-align \ -Wcast-function-type \ - -Wcast-qual + -Wcast-qual \ + -Wnull-dereference # Debugging/Optimization ifeq ($(DEBUG), 1) diff --git a/hw/bsp/samg55xplained/board.mk b/hw/bsp/samg55xplained/board.mk index f9396cb30..deff6944c 100644 --- a/hw/bsp/samg55xplained/board.mk +++ b/hw/bsp/samg55xplained/board.mk @@ -12,7 +12,7 @@ CFLAGS += \ -DCFG_TUSB_MCU=OPT_MCU_SAMG # suppress following warnings from mcu driver -CFLAGS += -Wno-error=undef -Wno-error=cast-qual +CFLAGS += -Wno-error=undef -Wno-error=cast-qual -Wno-error=null-dereference ASF_DIR = hw/mcu/microchip/samg55 diff --git a/src/portable/nuvoton/nuc505/dcd_nuc505.c b/src/portable/nuvoton/nuc505/dcd_nuc505.c index ea5a8bea5..11d71a285 100644 --- a/src/portable/nuvoton/nuc505/dcd_nuc505.c +++ b/src/portable/nuvoton/nuc505/dcd_nuc505.c @@ -144,7 +144,9 @@ static USBD_EP_T *ep_entry(uint8_t ep_addr, bool add) enum ep_enum ep_index; struct xfer_ctl_t *xfer; - for (ep_index = PERIPH_EPA, xfer = &xfer_table[PERIPH_EPA], ep = USBD->EP; ep_index < PERIPH_MAX_EP; ep_index++, xfer++, ep++) + for (ep_index = PERIPH_EPA, xfer = &xfer_table[PERIPH_EPA], ep = USBD->EP; + ep_index < PERIPH_MAX_EP; + ep_index++, xfer++, ep++) { if (add) { @@ -396,6 +398,7 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t to /* mine the data for the information we need */ tusb_dir_t dir = tu_edpt_dir(ep_addr); USBD_EP_T *ep = ep_entry(ep_addr, false); + TU_ASSERT(ep); struct xfer_ctl_t *xfer = &xfer_table[ep - USBD->EP]; /* store away the information we'll needing now and later */ @@ -457,6 +460,7 @@ void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) if (tu_edpt_number(ep_addr)) { USBD_EP_T *ep = ep_entry(ep_addr, false); + TU_ASSERT(ep, ); ep->EPRSPCTL = (ep->EPRSPCTL & 0xf7) | USBD_EPRSPCTL_HALT_Msk; } else @@ -472,6 +476,7 @@ void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) if (tu_edpt_number(ep_addr)) { USBD_EP_T *ep = ep_entry(ep_addr, false); + TU_ASSERT(ep, ); ep->EPRSPCTL = USBD_EPRSPCTL_TOGGLE_Msk; } }