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 <l...@metafoo.de>
---
 src/output/srzip.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/output/srzip.c b/src/output/srzip.c
index 8d01e5f..bfc42b2 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;
-- 
2.1.4


------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
sigrok-devel mailing list
sigrok-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sigrok-devel

Reply via email to