Revision: 13446
http://sourceforge.net/p/foray/code/13446
Author: victormote
Date: 2025-04-20 10:35:19 +0000 (Sun, 20 Apr 2025)
Log Message:
-----------
Fix some issues with signedness revealed by the Checker Framework.
Modified Paths:
--------------
trunk/foray/foray-primitive/src/main/java/org/foray/primitive/ByteUtils.java
trunk/foray/foray-primitive/src/main/java/org/foray/primitive/StringUtils.java
trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/NibbleArrayBuilder.java
Modified: trunk/foray/foray-primitive/src/main/java/org/foray/primitive/ByteUtils.java
===================================================================
--- trunk/foray/foray-primitive/src/main/java/org/foray/primitive/ByteUtils.java 2025-04-19 23:49:48 UTC (rev 13445)
+++ trunk/foray/foray-primitive/src/main/java/org/foray/primitive/ByteUtils.java 2025-04-20 10:35:19 UTC (rev 13446)
@@ -104,7 +104,8 @@
* @return The ASCII byte representing the value of the high-order nibble of {@code inputByte}.
*/
public static byte toHexCharHigh(final byte inputByte) {
- byte index = (byte) (inputByte >>> PrimitiveConstants.BITS_PER_NIBBLE);
+ /* Since we mask the high-order bits anyway, we can safely use the signed shift. */
+ byte index = (byte) (inputByte >> PrimitiveConstants.BITS_PER_NIBBLE);
index &= PrimitiveConstants.MAX_4_BIT_UNSIGNED_BYTE;
return (byte) HEX_CHARS.charAt(index);
}
Modified: trunk/foray/foray-primitive/src/main/java/org/foray/primitive/StringUtils.java
===================================================================
--- trunk/foray/foray-primitive/src/main/java/org/foray/primitive/StringUtils.java 2025-04-19 23:49:48 UTC (rev 13445)
+++ trunk/foray/foray-primitive/src/main/java/org/foray/primitive/StringUtils.java 2025-04-20 10:35:19 UTC (rev 13446)
@@ -435,13 +435,8 @@
final StringBuilder buffer = new StringBuilder();
for (int i = 0; i < value.length; i++) {
- buffer.append(
- HEXADECIMAL_DIGITS[(value[i]
- >>> PrimitiveConstants.BITS_PER_NIBBLE)
- & PrimitiveConstants.MAX_4_BIT_UNSIGNED_BYTE]);
- buffer.append(
- HEXADECIMAL_DIGITS[value[i]
- & PrimitiveConstants.MAX_4_BIT_UNSIGNED_BYTE]);
+ buffer.append((char) ByteUtils.toHexCharHigh(value[i]));
+ buffer.append((char) ByteUtils.toHexCharLow(value[i]));
}
return buffer.toString();
Modified: trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/NibbleArrayBuilder.java
===================================================================
--- trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/NibbleArrayBuilder.java 2025-04-19 23:49:48 UTC (rev 13445)
+++ trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/NibbleArrayBuilder.java 2025-04-20 10:35:19 UTC (rev 13446)
@@ -190,9 +190,9 @@
nibbleValue = BitUtils.maskHighOrderBits(byteValue);
} else {
/* If the index is even, return just the high-order bits. */
- nibbleValue = (byte) (byteValue >>> PrimitiveConstants.BITS_PER_NIBBLE);
+ nibbleValue = (byte) (byteValue >> PrimitiveConstants.BITS_PER_NIBBLE);
/* Have to mask out the high-order bits after the cast, in case the shifted value has
- * the high-order bit set, and therefore looks negative -- in that case the caset sets
+ * the high-order bit set, and therefore looks negative -- in that case the cast sets
* all of the high-order bits. */
nibbleValue = BitUtils.maskHighOrderBits(nibbleValue);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|