Commit a8fdf906 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

araw: avoid underflow in conversion

Cast to positive numbers to int explicitly before computing the
difference, so the result will be signed correctly.
parent 44bed4b3
...@@ -609,18 +609,20 @@ static void F64IDecode( void *outp, const uint8_t *in, unsigned samples ) ...@@ -609,18 +609,20 @@ static void F64IDecode( void *outp, const uint8_t *in, unsigned samples )
} }
} }
static int16_t dat12tos16( uint_fast16_t y ) static int_fast16_t dat12tos16( uint_fast16_t y )
{ {
static const uint16_t diff[16] = { static const int16_t diff[16] = {
0x0000, 0x0000, 0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600, 0x0000, 0x0000, 0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600,
0x0A00, 0x0B00, 0x0C00, 0x0D00, 0x0E00, 0x0F00, 0x1000, 0x1000 }; 0x0A00, 0x0B00, 0x0C00, 0x0D00, 0x0E00, 0x0F00, 0x1000, 0x1000,
};
static const uint8_t shift[16] = { static const uint8_t shift[16] = {
0, 0, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 0, 0 }; 0, 0, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 0, 0
};
assert(y < 0x1000); assert(y < 0x1000);
int d = y >> 8; int d = y >> 8;
return (y - diff[d]) << shift[d]; return ((int)y - diff[d]) << shift[d];
} }
static void DAT12Decode( void *outp, const uint8_t *in, unsigned samples ) static void DAT12Decode( void *outp, const uint8_t *in, unsigned samples )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment