From 9377fd6901dd9c7b5361a9ce5c01a99cc6761750 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 3 Nov 2023 22:34:49 +0700 Subject: [PATCH] fix -Werror=null-dereference warning --- src/host/usbh.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/host/usbh.c b/src/host/usbh.c index fb4fbe3cb..d8fff9905 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -554,8 +554,12 @@ bool tuh_control_xfer (tuh_xfer_t* xfer) { // Check if device is still connected (enumerating for dev0) uint8_t const daddr = xfer->daddr; - if ( daddr == 0 && !_dev0.enumerating) return false; - if ( daddr != 0 && get_device(daddr)->connected == 0) return false; + if ( daddr == 0 ) { + if (!_dev0.enumerating) return false; + } else { + usbh_device_t const* dev = get_device(daddr); + if (dev && dev->connected == 0) return false; + } // pre-check to help reducing mutex lock TU_VERIFY(_ctrl_xfer.stage == CONTROL_STAGE_IDLE);