Saturate return value of fix2byte

This commit is contained in:
Kp 2021-06-28 03:37:51 +00:00
parent 7cba352c19
commit 659be87a5b

View file

@ -73,9 +73,15 @@ struct RAIIMix_Chunk : public Mix_Chunk
RAIIMix_Chunk &operator=(const RAIIMix_Chunk &) = delete; RAIIMix_Chunk &operator=(const RAIIMix_Chunk &) = delete;
}; };
static int fix2byte(const fix f) static uint8_t fix2byte(const fix f)
{ {
return (f / 256) % 256; if (f >= UINT8_MAX << 8)
/* Values greater than this would produce incorrect results if
* shifted and truncated. As a special case, coerce such values
* to the largest representable return value.
*/
return UINT8_MAX;
return f >> 8;
} }
uint8_t digi_initialised; uint8_t digi_initialised;