Skip to content

Commit ba6ea44

Browse files
dfa1claude
andcommitted
fix: explicit & 0xff on byte | int bit-pack writes
SonarCloud S3034 flags 7 sites where a byte is OR'd with a positive int mask, then cast back to byte. Behaviour was already correct (the cast truncates the sign-extended upper bits), but the intermediate int result is sign-extended and would be wrong if anyone read it before the cast. Adding {@code & 0xff} on the byte side makes the unsigned-bit intent explicit and quiet the rule. Also drops the trivially-passing KeyTest#navigationKeysAreDistinct (S5845): {@code isNotSameAs} between two distinct enum singletons is always true at compile time. The PatternMatching test already covers distinctness functionally. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent f20e80d commit ba6ea44

8 files changed

Lines changed: 7 additions & 17 deletions

File tree

cli/src/test/java/io/github/dfa1/vortex/cli/tui/term/KeyTest.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ void allArrowsAreSealedKeyVariants() {
4040
assertThat(Key.ArrowLeft.INSTANCE).isInstanceOf(Key.class);
4141
assertThat(Key.ArrowRight.INSTANCE).isInstanceOf(Key.class);
4242
}
43-
44-
@Test
45-
void navigationKeysAreDistinct() {
46-
// Given / When / Then — each singleton must be its own type;
47-
// a switch in TUI code dispatches by identity-equivalent enum match.
48-
assertThat(Key.PageUp.INSTANCE).isNotSameAs(Key.PageDown.INSTANCE);
49-
assertThat(Key.Home.INSTANCE).isNotSameAs(Key.End.INSTANCE);
50-
assertThat(Key.Enter.INSTANCE).isNotSameAs(Key.Escape.INSTANCE);
51-
assertThat(Key.Eof.INSTANCE).isNotSameAs(Key.Escape.INSTANCE);
52-
}
5343
}
5444

5545
@Nested

inspector/src/main/java/io/github/dfa1/vortex/inspect/ZonedStatsSchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static List<Stat> presentStats(ByteBuffer metadata) {
110110
while (mb.hasRemaining()) {
111111
byte b = mb.get();
112112
for (int bit = 0; bit < 8; bit++) {
113-
if ((b & (1 << bit)) != 0 && bitIndex < all.length) {
113+
if (((b & 0xff) & (1 << bit)) != 0 && bitIndex < all.length) {
114114
out.add(all[bitIndex]);
115115
}
116116
bitIndex++;

reader/src/main/java/io/github/dfa1/vortex/reader/array/MaterializedBoolArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ MemorySegment buffer() {
4242
@Override
4343
public boolean getBoolean(long i) {
4444
byte b = buffer.get(ValueLayout.JAVA_BYTE, i >>> 3);
45-
return (b & (1 << (i & 7))) != 0;
45+
return ((b & 0xff) & (1 << (i & 7))) != 0;
4646
}
4747
}

reader/src/main/java/io/github/dfa1/vortex/reader/decode/ByteBoolEncodingDecoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public Array decode(DecodeContext ctx) {
3636
if (bytes.get(ValueLayout.JAVA_BYTE, i) != 0) {
3737
long byteIdx = i >>> 3;
3838
byte cur = packed.get(ValueLayout.JAVA_BYTE, byteIdx);
39-
packed.set(ValueLayout.JAVA_BYTE, byteIdx, (byte) (cur | (1 << (i & 7))));
39+
packed.set(ValueLayout.JAVA_BYTE, byteIdx, (byte) ((cur & 0xff) | (1 << (i & 7))));
4040
}
4141
}
4242
return new MaterializedBoolArray(ctx.dtype(), n, packed);

reader/src/main/java/io/github/dfa1/vortex/reader/decode/RleEncodingDecoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public Array decode(DecodeContext ctx) {
131131
if (indicesValidity.getBoolean(offset + j)) {
132132
int byteIdx = (int) (j >>> 3);
133133
byte current = validityBuf.get(ValueLayout.JAVA_BYTE, byteIdx);
134-
validityBuf.set(ValueLayout.JAVA_BYTE, byteIdx, (byte) (current | (1 << (j & 7))));
134+
validityBuf.set(ValueLayout.JAVA_BYTE, byteIdx, (byte) ((current & 0xff) | (1 << (j & 7))));
135135
}
136136
}
137137
BoolArray outputValidity = new MaterializedBoolArray(new DType.Bool(false), rowCount, validityBuf);

reader/src/main/java/io/github/dfa1/vortex/reader/decode/RunEndEncodingDecoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ private static Array expandBool(
190190
if (val) {
191191
long byteIdx = outIdx >>> 3;
192192
byte cur = out.get(ValueLayout.JAVA_BYTE, byteIdx);
193-
out.set(ValueLayout.JAVA_BYTE, byteIdx, (byte) (cur | (1 << (outIdx & 7))));
193+
out.set(ValueLayout.JAVA_BYTE, byteIdx, (byte) ((cur & 0xff) | (1 << (outIdx & 7))));
194194
}
195195
}
196196
logicalPos = runEnd;

reader/src/main/java/io/github/dfa1/vortex/reader/decode/SparseEncodingDecoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private static Array decodeBool(
122122
long pos = readUnsignedIdx(idxSeg, SegmentBroadcast.elementOffset(idxSeg, i, idxBytes), indicesPtype) - offset;
123123
long byteIdx = pos >>> 3;
124124
byte cur = out.get(ValueLayout.JAVA_BYTE, byteIdx);
125-
out.set(ValueLayout.JAVA_BYTE, byteIdx, (byte) (cur | (1 << (pos & 7))));
125+
out.set(ValueLayout.JAVA_BYTE, byteIdx, (byte) ((cur & 0xff) | (1 << (pos & 7))));
126126
}
127127
}
128128
}

writer/src/main/java/io/github/dfa1/vortex/writer/encode/BoolEncodingEncoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private static MemorySegment encodeBool(boolean[] data, Arena arena) {
2727
if (data[i]) {
2828
long byteIdx = i / 8;
2929
byte cur = seg.get(ValueLayout.JAVA_BYTE, byteIdx);
30-
seg.set(ValueLayout.JAVA_BYTE, byteIdx, (byte) (cur | (1 << (i % 8))));
30+
seg.set(ValueLayout.JAVA_BYTE, byteIdx, (byte) ((cur & 0xff) | (1 << (i % 8))));
3131
}
3232
}
3333
return seg;

0 commit comments

Comments
 (0)