Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a84419ca authored by László Dávid's avatar László Dávid Committed by Steve Kondik
Browse files

32 bit int shifted by 36 bits at BluetoothMasObexServer.getUint32BigEndian

I have found the bug with the FindBugs tool (http://findbugs.sourceforge.net)

The FindBugs description is:

32 bit int shifted by 36 bits at BluetoothMasObexServer.java:[line: 189]

32 bit int shifted by an amount not in the range 0..31
The code performs shift of a 32 bit int by a constant amount outside
the range 0..31. The effect of this is to use the lower 5 bits of the
integer value to decide how much to shift by
(e.g., shifting by 40 bits is the same as shifting by 8 bits,
and shifting by 32 bits is the same as shifting by zero bits).
This probably isn't what was expected, and it is at least confusing.

Bug kind and pattern: BSHIFT - ICAST_BAD_SHIFT_AMOUNT

Change-Id: I45748b7e980c28a75a4210a8974aa00cd732e1f8
parent 249cf075
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -180,15 +180,17 @@ public class BluetoothMasObexServer extends ServerRequestHandler {

        private final int getUint16BigEndian(byte b1, byte b2) {
            int retVal;
            retVal = (int) ((0x0000FF00 & (int) (b1 << 0x8)) | (0x000000FF & (int) b2));
            retVal = (((int) b1 & 0xFF) << 8) |
                      ((int) b2 & 0xFF);
            return retVal;
        }

        private final long getUint32BigEndian(byte b1, byte b2, byte b3, byte b4) {
            long retVal;
            retVal = (long) ((0xFF000000 & (long) (b1 << 0x24))
                    | (0x00FF0000 & (long) (b2 << 0x16))
                    | (0x0000FF00 & (long) (b3 << 0x8)) | (0x000000FF & (long) b4));
            retVal = (((long) b1 & 0xFF) << 24) |
                     (((long) b2 & 0xFF) << 16) |
                     (((long) b3 & 0xFF) << 8) |
                      ((long) b4 & 0xFF);
            return retVal;
        }