]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/dreamsourcelab-dslogic/protocol.c
dreamsourcelab-dslogic: avoid division by zero
[libsigrok.git] / src / hardware / dreamsourcelab-dslogic / protocol.c
index 3b4848eead90e944205a995588d7847c181de9bc..863b4e3bac6f9a7ba88a6f25d768440dcc935c91 100644 (file)
@@ -733,10 +733,12 @@ static void deinterleave_buffer(const uint8_t *src, size_t length,
                for (int bit = 0; bit != 64; bit++) {
                        const uint64_t *word_ptr = src_ptr;
                        sample = 0;
-                       for (size_t channel = 0; channel != channel_count;
+                       for (unsigned int channel = 0; channel != 16;
                                channel++) {
-                               if ((channel_mask & (1 << channel)) &&
-                                       (*word_ptr++ & (1ULL << bit)))
+                               const uint16_t m = channel_mask >> channel;
+                               if (!m)
+                                       break;
+                               if ((m & 1) && ((*word_ptr++ >> bit) & 1ULL))
                                        sample |= 1 << channel;
                        }
                        *dst_ptr++ = sample;
@@ -912,6 +914,8 @@ static size_t get_buffer_size(const struct sr_dev_inst *sdi)
         */
        const size_t block_size = enabled_channel_count(sdi) * 512;
        const size_t s = 10 * to_bytes_per_ms(sdi);
+       if (!block_size)
+               return s;
        return ((s + block_size - 1) / block_size) * block_size;
 }