]> sigrok.org Git - libsigrok.git/commitdiff
filter.c: Fix endianness bug in sr_filter_probes
authorMarcus Comstedt <redacted>
Sat, 7 Dec 2013 16:09:06 +0000 (17:09 +0100)
committerBert Vermeulen <redacted>
Sat, 7 Dec 2013 17:27:38 +0000 (18:27 +0100)
filter.c

index 8a00e76dfe5413dd3e22e035e6384776e8c201d3..005b8984c8507ccf5a7e32e7e1935f9654d539ce 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -106,7 +106,7 @@ SR_API int sr_filter_probes(unsigned int in_unitsize, unsigned int out_unitsize,
        unsigned int in_offset, out_offset;
        int *probelist, out_bit;
        unsigned int i;
-       uint64_t sample_in, sample_out;
+       uint8_t *sample_in, *sample_out;
 
        if (!probe_array) {
                sr_err("%s: probe_array was NULL", __func__);
@@ -151,14 +151,15 @@ SR_API int sr_filter_probes(unsigned int in_unitsize, unsigned int out_unitsize,
        /* If we reached this point, not all probes are used, so "compress". */
        in_offset = out_offset = 0;
        while (in_offset <= length_in - in_unitsize) {
-               memcpy(&sample_in, data_in + in_offset, in_unitsize);
-               sample_out = out_bit = 0;
+               sample_in = data_in + in_offset;
+               sample_out = (*data_out) + out_offset;
+               memset(sample_out, 0, out_unitsize);
+               out_bit = 0;
                for (i = 0; i < probe_array->len; i++) {
-                       if (sample_in & (1 << (probelist[i])))
-                               sample_out |= (1 << out_bit);
+                       if (sample_in[probelist[i]>>3] & (1 << (probelist[i]&7)))
+                               sample_out[out_bit>>3] |= (1 << (out_bit&7));
                        out_bit++;
                }
-               memcpy((*data_out) + out_offset, &sample_out, out_unitsize);
                in_offset += in_unitsize;
                out_offset += out_unitsize;
        }