From: Gerhard Sittig Date: Sun, 16 Jun 2019 09:17:51 +0000 (+0200) Subject: microchip-pickit2: silence compiler warnings (NULL dereference) X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=fbe1481a4cda038891d24679fd58e89375da17fe;p=libsigrok.git microchip-pickit2: silence compiler warnings (NULL dereference) Check pointers for validity before dereferencing them. This silences the following compiler warnings: ../src/hardware/microchip-pickit2/api.c:275:8: warning: Access to field 'conn' results in a dereference of a null pointer (loaded from variable 'sdi') if (!sdi->conn) ../src/hardware/microchip-pickit2/api.c:281:10: warning: Access to field 'samplerates' results in a dereference of a null pointer (loaded from variable 'devc') rate = devc->samplerates[devc->curr_samplerate_idx]; ../src/hardware/microchip-pickit2/api.c:287:11: warning: Access to field 'captureratios' results in a dereference of a null pointer (loaded from variable 'devc') ratio = devc->captureratios[devc->curr_captureratio_idx]; --- diff --git a/src/hardware/microchip-pickit2/api.c b/src/hardware/microchip-pickit2/api.c index d8a75728..79c79d3e 100644 --- a/src/hardware/microchip-pickit2/api.c +++ b/src/hardware/microchip-pickit2/api.c @@ -267,21 +267,27 @@ static int config_get(uint32_t key, GVariant **data, (void)cg; devc = sdi ? sdi->priv : NULL; + usb = sdi ? sdi->conn : NULL; switch (key) { case SR_CONF_CONN: - if (!sdi->conn) + if (!usb) return SR_ERR_ARG; - usb = sdi->conn; *data = g_variant_new_printf("%d.%d", usb->bus, usb->address); return SR_OK; case SR_CONF_SAMPLERATE: + if (!devc) + return SR_ERR_ARG; rate = devc->samplerates[devc->curr_samplerate_idx]; *data = g_variant_new_uint64(rate); return SR_OK; case SR_CONF_LIMIT_SAMPLES: + if (!devc) + return SR_ERR_ARG; return sr_sw_limits_config_get(&devc->sw_limits, key, data); case SR_CONF_CAPTURE_RATIO: + if (!devc) + return SR_ERR_ARG; ratio = devc->captureratios[devc->curr_captureratio_idx]; *data = g_variant_new_uint64(ratio); return SR_OK;