]> sigrok.org Git - libsigrok.git/commitdiff
yokogawa-dlm: fix several compiler warnings (assignment, memory)
authorGerhard Sittig <redacted>
Fri, 9 Feb 2018 18:32:12 +0000 (19:32 +0100)
committerUwe Hermann <redacted>
Fri, 9 Feb 2018 20:37:40 +0000 (21:37 +0100)
Check pointers' validity before dereferencing them. Release partially
allocated memory in an error path. Remove an assignment which never took
effect.

This was reported by clang's scan-build.

src/hardware/yokogawa-dlm/api.c
src/hardware/yokogawa-dlm/protocol.c

index 9d5660761b0549ff0e19c5a440fe054a8126be79..f80e83dceb7e91537252d05b37a516e12e225ac3 100644 (file)
@@ -164,6 +164,8 @@ static int check_channel_group(struct dev_context *devc,
 {
        const struct scope_config *model;
 
+       if (!devc)
+               return CG_INVALID;
        model = devc->model_config;
 
        if (!cg)
@@ -284,8 +286,6 @@ static int config_set(uint32_t key, GVariant *data,
        state = devc->model_state;
        update_sample_rate = FALSE;
 
-       ret = SR_ERR_NA;
-
        switch (key) {
        case SR_CONF_LIMIT_FRAMES:
                devc->frame_limit = g_variant_get_uint64(data);
@@ -409,6 +409,8 @@ static int config_list(uint32_t key, GVariant **data,
                        *data = g_variant_new_strv(ARRAY_AND_SIZE(dlm_trigger_slopes));
                        return SR_OK;
                case SR_CONF_NUM_HDIV:
+                       if (!model)
+                               return SR_ERR_ARG;
                        *data = g_variant_new_uint32(model->num_xdivs);
                        return SR_OK;
                default:
index cc822eb462feb1f0fbf8ddaafa901832341a22d4..1bd863ee1545a645139111eaa78993657172758d 100644 (file)
@@ -777,9 +777,13 @@ SR_PRIV int dlm_device_init(struct sr_dev_inst *sdi, int model_index)
 
        devc->analog_groups = g_malloc0(sizeof(struct sr_channel_group*) *
                        scope_models[model_index].analog_channels);
-
        devc->digital_groups = g_malloc0(sizeof(struct sr_channel_group*) *
                        scope_models[model_index].pods);
+       if (!devc->analog_groups || !devc->digital_groups) {
+               g_free(devc->analog_groups);
+               g_free(devc->digital_groups);
+               return SR_ERR_MALLOC;
+       }
 
        /* Add analog channels, each in its own group. */
        for (i = 0; i < scope_models[model_index].analog_channels; i++) {