Skip to content
Browse files

32 bit int shifted by 36 bits at BluetoothMasObexServer.getUint32BigE…

…ndian

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
  • Loading branch information...
1 parent 9566c3e commit 212539cdadebe147cc93d4050db6440d96e4d16e @dlaszlo dlaszlo committed with cyanogen Oct 22, 2012
Showing with 6 additions and 4 deletions.
  1. +6 −4 src/org/codeaurora/bluetooth/map/BluetoothMasObexServer.java
View
10 src/org/codeaurora/bluetooth/map/BluetoothMasObexServer.java
@@ -188,15 +188,17 @@ public final boolean isMaxListCountZero() {
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;
}

0 comments on commit 212539c

Please sign in to comment.
Something went wrong with that request. Please try again.