Skip to content

Commit b1df8ca

Browse files
committed
Fix bugs found by sonar, mainly adding "& 0xff" to not promote int
1 parent 8985a4a commit b1df8ca

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/main/java/at/favre/lib/bytes/Base64.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static byte[] decode(CharSequence in) {
9393
}
9494

9595
// Append this char's 6 bits to the word.
96-
word = (word << 6) | (byte) bits;
96+
word = (word << 6) | (byte) bits & 0xff;
9797

9898
// For every 4 chars of input, we accumulate 24 bits of output. Emit 3 bytes.
9999
inCount++;

src/main/java/at/favre/lib/bytes/Util.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ static byte[] shiftLeft(byte[] byteArray, int shiftBitCount, ByteOrder byteOrder
309309
byte src = byteArray[sourceIndex];
310310
byte dst = (byte) (src << shiftMod);
311311
if (sourceIndex + 1 < byteArray.length) {
312-
dst |= byteArray[sourceIndex + 1] >>> (8 - shiftMod) & carryMask;
312+
dst |= byteArray[sourceIndex + 1] >>> (8 - shiftMod) & carryMask & 0xff;
313313
}
314314
byteArray[i] = dst;
315315
}
@@ -323,7 +323,7 @@ static byte[] shiftLeft(byte[] byteArray, int shiftBitCount, ByteOrder byteOrder
323323
byte src = byteArray[sourceIndex];
324324
byte dst = (byte) (src << shiftMod);
325325
if (sourceIndex - 1 >= 0) {
326-
dst |= byteArray[sourceIndex - 1] >>> (8 - shiftMod) & carryMask;
326+
dst |= byteArray[sourceIndex - 1] >>> (8 - shiftMod) & carryMask & 0xff;
327327
}
328328
byteArray[i] = dst;
329329
}
@@ -365,7 +365,7 @@ static byte[] shiftRight(byte[] byteArray, int shiftBitCount, ByteOrder byteOrde
365365
byte src = byteArray[sourceIndex];
366366
byte dst = (byte) ((0xff & src) >>> shiftMod);
367367
if (sourceIndex - 1 >= 0) {
368-
dst |= byteArray[sourceIndex - 1] << (8 - shiftMod) & carryMask;
368+
dst |= byteArray[sourceIndex - 1] << (8 - shiftMod) & carryMask & 0xff;
369369
}
370370
byteArray[i] = dst;
371371
}
@@ -379,7 +379,7 @@ static byte[] shiftRight(byte[] byteArray, int shiftBitCount, ByteOrder byteOrde
379379
byte src = byteArray[sourceIndex];
380380
byte dst = (byte) ((0xff & src) >>> shiftMod);
381381
if (sourceIndex + 1 < byteArray.length) {
382-
dst |= byteArray[sourceIndex + 1] << (8 - shiftMod) & carryMask;
382+
dst |= byteArray[sourceIndex + 1] << (8 - shiftMod) & carryMask & 0xff;
383383
}
384384
byteArray[i] = dst;
385385
}

0 commit comments

Comments
 (0)