]> sigrok.org Git - libsigrok.git/commitdiff
scpi-pps: silence potential NULL dereference compiler warning
authorGerhard Sittig <redacted>
Fri, 9 Feb 2018 18:29:08 +0000 (19:29 +0100)
committerUwe Hermann <redacted>
Fri, 9 Feb 2018 20:37:40 +0000 (21:37 +0100)
Check pointers' validity before dereferencing them.

This was reported by clang's scan-build.

src/hardware/scpi-pps/api.c

index 6ffc17d4f7ca1d03fcd3e7862d969edb346bad83..9158933dedf5e9bc44c95780ddabe34a3f251409 100644 (file)
@@ -525,10 +525,12 @@ static int config_list(uint32_t key, GVariant **data,
                        return std_opts_config_list(key, data, sdi, cg,
                                ARRAY_AND_SIZE(scanopts),
                                ARRAY_AND_SIZE(drvopts),
-                               (devc) ? devc->device->devopts : NULL,
-                               (devc) ? devc->device->num_devopts : 0);
+                               (devc && devc->device) ? devc->device->devopts : NULL,
+                               (devc && devc->device) ? devc->device->num_devopts : 0);
                        break;
                case SR_CONF_CHANNEL_CONFIG:
+                       if (!devc || !devc->device)
+                               return SR_ERR_ARG;
                        /* Not used. */
                        i = 0;
                        if (devc->device->features & PPS_INDEPENDENT)
@@ -557,6 +559,8 @@ static int config_list(uint32_t key, GVariant **data,
                 * specification for use in series or parallel mode.
                 */
                ch = cg->channels->data;
+               if (!devc || !devc->device)
+                       return SR_ERR_ARG;
                ch_spec = &(devc->device->channels[ch->index]);
 
                switch (key) {