[sane-devel] Plustek backend: incorrect rounding

Aurelien Jarno lists@aurel32.net
Fri, 6 Dec 2002 21:36:28 +0100


--KsGdsel6WgEHnImy
Content-Type: text/plain; charset=iso-8859-15
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hello !

I am forwarding the following bug reported via the Debian BTS:

| In backend/plustek-usbimg.c, line 1363:
|
| if(!(a_bRegs[0x4e] =3D (u_char)ceil(dw / (4 * hw->wDRAMSize))))
|
| dw and hw->wDRAMSize are both integral types, meaning the division is
| done in integer arithmetic, the result is always rounded down instead of
| up, and the ceil() is left meaningless.

The following patch should fix that.

Aurelien


Index: sane-backends/backend/plustek-usbimg.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file:
/cvsroot/external/sane/sane-backends/backend/plustek-usbimg.c,v
retrieving revision 1.9
diff -u -1 -b -p -r1.9 plustek-usbimg.c
--- plustek-usbimg.c    2002/10/15 18:02:39     1.9
+++ plustek-usbimg.c    2002/12/06 19:57:07
@@ -1362,3 +1362,3 @@ static SANE_Int usb_ReadData( struct Plu
                {
-                       if(!(a_bRegs[0x4e] =3D (u_char)ceil(dw / (4 * hw->w=
DRAMSize))))		=09
+                       if(!(a_bRegs[0x4e] =3D (u_char)ceil(dw / (4.0 * hw-=
>wDRAMSize))))
                                a_bRegs[0x4e] =3D 1;

--KsGdsel6WgEHnImy
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (GNU/Linux)

iD8DBQE98QpMw3ao2vG823MRAuSFAKCH2RAV5Hz6IawCL/UEqWUQ3b+0tQCfajqS
XRfH1e1hlumb77SlCVe93C4=
=PAOQ
-----END PGP SIGNATURE-----

--KsGdsel6WgEHnImy--