From: Gerhard Sittig Date: Fri, 9 Feb 2018 18:32:12 +0000 (+0100) Subject: yokogawa-dlm: fix several compiler warnings (assignment, memory) X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=93b5cd6919a31f530cd87042b11a28827f4a7fa6 yokogawa-dlm: fix several compiler warnings (assignment, memory) 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. --- diff --git a/src/hardware/yokogawa-dlm/api.c b/src/hardware/yokogawa-dlm/api.c index 9d566076..f80e83dc 100644 --- a/src/hardware/yokogawa-dlm/api.c +++ b/src/hardware/yokogawa-dlm/api.c @@ -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: diff --git a/src/hardware/yokogawa-dlm/protocol.c b/src/hardware/yokogawa-dlm/protocol.c index cc822eb4..1bd863ee 100644 --- a/src/hardware/yokogawa-dlm/protocol.c +++ b/src/hardware/yokogawa-dlm/protocol.c @@ -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++) {