plustek: Adjust gain calculation to avoid calling labs()

labs() has a signed parameter. However the argument to it here was the
difference between two unsigned values, which itself remains unsigned.
GCC warned that using this in labs() might not have the intended result.

By definition though, dwInc >= m_dwIdealGain >= dwDec, so labs() is not
even needed in this expression.
merge-requests/701/head
David Ward 2022-03-08 19:00:00 -05:00
rodzic 5576d03afd
commit 2efdd5a334
1 zmienionych plików z 1 dodań i 1 usunięć

Wyświetl plik

@ -685,7 +685,7 @@ static u_char usb_GetNewGain( Plustek_Device *dev, u_short wMax, int channel )
dwInc = (u_long)((0.93 + ceil (dRatio) * 0.067) * wMax / dAmp);
dwDec = (u_long)((0.93 + floor (dRatio) * 0.067) * wMax / dAmp);
if((dwInc >= 0xff00) ||
(labs (dwInc - m_dwIdealGain) > labs(dwDec - m_dwIdealGain))) {
(dwInc - m_dwIdealGain > m_dwIdealGain - dwDec)) {
bGain = (u_char)floor(dRatio);
} else {
bGain = (u_char)ceil(dRatio);