From: Lars-Peter Clausen Date: Thu, 28 Apr 2016 15:43:15 +0000 (+0200) Subject: srzip: Fix handling of analog channels with index 0 X-Git-Tag: libsigrok-0.5.0~415 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=9906dbf5a4f26e630b76e8f56e80d6b085b90446;p=libsigrok.git srzip: Fix handling of analog channels with index 0 0 is a valid index for a channel. Using it as the value for the terminating entry of analog_index_map causes zip_append_analog() to falsely assume that no channel was found when a packet for a channel with index 0 was received. This prevents the data for the channel to be added to the sigrok session file. Instead use -1, which is not a valid channel index, as the terminating entry value. Signed-off-by: Lars-Peter Clausen --- diff --git a/src/output/srzip.c b/src/output/srzip.c index 8d01e5f6..bfc42b21 100644 --- a/src/output/srzip.c +++ b/src/output/srzip.c @@ -140,8 +140,9 @@ static int zip_create(const struct sr_output *o) g_key_file_set_integer(meta, devgroup, "total analog", enabled_analog_channels); /* Make the array one entry larger than needed so we can use the final - * 0 as terminator. */ + * entry as terminator, which is set to -1. */ outc->analog_index_map = g_malloc0(sizeof(gint) * (enabled_analog_channels + 1)); + outc->analog_index_map[enabled_analog_channels] = -1; index = 0; for (l = o->sdi->channels; l; l = l->next) { @@ -342,10 +343,10 @@ static int zip_append_analog(const struct sr_output *o, /* When reading the file, analog channels must be consecutive. * Thus we need a global channel index map as we don't know in * which order the channel data comes in. */ - for (index = 0; outc->analog_index_map[index]; index++) + for (index = 0; outc->analog_index_map[index] != -1; index++) if (outc->analog_index_map[index] == channel->index) break; - if (!outc->analog_index_map[index]) + if (outc->analog_index_map[index] == -1) return SR_ERR_ARG; /* Channel index was not in the list */ index += outc->first_analog_index;