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 <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2016-04-28 17:43:15 +02:00 committed by Uwe Hermann
parent 4def782b6e
commit 9906dbf5a4
1 changed files with 4 additions and 3 deletions

View File

@ -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;