From: Martin Ling Date: Mon, 7 Sep 2015 08:15:52 +0000 (+0100) Subject: sr_analog_to_float: Avoid comparison between signed and unsigned. X-Git-Tag: libsigrok-0.4.0~261 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=b07a1b04e5da31e02b45ddd32e6b006b0329e02c;p=libsigrok.git sr_analog_to_float: Avoid comparison between signed and unsigned. The check for p == q is basically checking whether p/q == 1. We should be normalising the rational before it gets here though, so in this case we should have p == q == 1 here. --- diff --git a/src/analog.c b/src/analog.c index db5ac1cf..dd23d4b4 100644 --- a/src/analog.c +++ b/src/analog.c @@ -173,7 +173,8 @@ SR_API int sr_analog_to_float(const struct sr_datafeed_analog2 *analog, if (analog->encoding->unitsize == sizeof(float) && analog->encoding->is_bigendian == bigendian - && (analog->encoding->scale.p == analog->encoding->scale.q) + && analog->encoding->scale.p == 1 + && analog->encoding->scale.q == 1 && analog->encoding->offset.p / (float)analog->encoding->offset.q == 0) { /* The data is already in the right format. */ memcpy(outbuf, analog->data, count * sizeof(float)); @@ -187,7 +188,8 @@ SR_API int sr_analog_to_float(const struct sr_datafeed_analog2 *analog, ((uint8_t *)outbuf)[i + (analog->encoding->unitsize - b)] = ((uint8_t *)analog->data)[i * analog->encoding->unitsize + b]; } - if (analog->encoding->scale.p != analog->encoding->scale.q) + if (analog->encoding->scale.p != 1 + || analog->encoding->scale.q != 1) outbuf[i] = (outbuf[i] * analog->encoding->scale.p) / analog->encoding->scale.q; offset = ((float)analog->encoding->offset.p / (float)analog->encoding->offset.q); outbuf[i] += offset;