]> sigrok.org Git - libsigrok.git/commitdiff
microchip-pickit2: silence compiler warnings (NULL dereference)
authorGerhard Sittig <redacted>
Sun, 16 Jun 2019 09:17:51 +0000 (11:17 +0200)
committerGerhard Sittig <redacted>
Sun, 21 Aug 2022 15:45:11 +0000 (17:45 +0200)
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];

src/hardware/microchip-pickit2/api.c

index d8a757283655496d10b9a2c2d26eed2c7c875694..79c79d3eae7286dfa78d39c5419190608b0fa10a 100644 (file)
@@ -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;