From: Marcus Comstedt Date: Sat, 7 Dec 2013 16:09:06 +0000 (+0100) Subject: filter.c: Fix endianness bug in sr_filter_probes X-Git-Tag: libsigrok-0.3.0~466 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=764e7bbfec52f0530f1f965879b0d81a7fc9acb2;p=libsigrok.git filter.c: Fix endianness bug in sr_filter_probes --- diff --git a/filter.c b/filter.c index 8a00e76d..005b8984 100644 --- 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; }