]> sigrok.org Git - libsigrok.git/commitdiff
atten-pps3xxx: silence NULL dereference compiler warnings
authorGerhard Sittig <redacted>
Thu, 8 Feb 2018 21:02:59 +0000 (22:02 +0100)
committerUwe Hermann <redacted>
Fri, 9 Feb 2018 20:34:17 +0000 (21:34 +0100)
Check pointers' validity before dereferencing them.

This was reported by clang's scan-build.

src/hardware/atten-pps3xxx/api.c

index f08671fb1081b28083601d0113c7afad8b4a0ccd..b82b9fb333cf9fd460764d638ce325f3e607caaf 100644 (file)
@@ -317,6 +317,8 @@ static int config_list(uint32_t key, GVariant **data,
                case SR_CONF_DEVICE_OPTIONS:
                        return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
                case SR_CONF_CHANNEL_CONFIG:
+                       if (!devc || !devc->model)
+                               return SR_ERR_ARG;
                        if (devc->model->channel_modes == CHANMODE_INDEPENDENT) {
                                /* The 1-channel models. */
                                *data = g_variant_new_strv(channel_modes, 1);
@@ -338,9 +340,13 @@ static int config_list(uint32_t key, GVariant **data,
                        *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg));
                        break;
                case SR_CONF_VOLTAGE_TARGET:
+                       if (!devc || !devc->model)
+                               return SR_ERR_ARG;
                        *data = std_gvar_min_max_step_array(devc->model->channels[channel].voltage);
                        break;
                case SR_CONF_CURRENT_LIMIT:
+                       if (!devc || !devc->model)
+                               return SR_ERR_ARG;
                        *data = std_gvar_min_max_step_array(devc->model->channels[channel].current);
                        break;
                default: