diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javatransient0/JavaTransient0Generator.java | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javatransient0/JavaTransient0Generator.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javatransient0/JavaTransient0Generator.java index 78cbca4..1999cc8 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javatransient0/JavaTransient0Generator.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javatransient0/JavaTransient0Generator.java @@ -225,6 +225,8 @@ public class JavaTransient0Generator implements Generator { private JavaMethodDeclaration generateDecodeInt8Method() { var statements = List.<JavaBlockStatement>of( + // InputStream.read() returns a byte of data as an int, so casting + // to a byte is safe. new JavaReturn(new JavaCast( JavaTypeRef.BYTE, generateInputStreamRead() @@ -267,6 +269,8 @@ public class JavaTransient0Generator implements Generator { ); if (bits > 32) { + // byteToWrite should only represent a byte of data, so + // casting to int is safe. byteToWrite = new JavaCast(JavaTypeRef.INT, byteToWrite); } @@ -334,6 +338,7 @@ public class JavaTransient0Generator implements Generator { )); statements.addAll(generateEncode( + // The length of a string is an int, so casting to long is safe. new JavaCast(JavaTypeRef.LONG, new JavaFieldAccess( new JavaRef(bytesVariableName), JavaIdentifier.of("length") @@ -383,6 +388,10 @@ public class JavaTransient0Generator implements Generator { Optional.of(new JavaMethodCall( new JavaRef(INPUT_STREAM_NAME), JavaIdentifier.of("readNBytes"), + // We've checked above that the length is less than + // Integer.MAX_VALUE, so casting to an int is safe. + // (This doesn't check for negatives, but readNBytes() fails for + // negative values anyway.) List.of(new JavaCast(JavaTypeRef.INT, new JavaRef(bytesLengthVariableName))) )) )); @@ -872,6 +881,7 @@ public class JavaTransient0Generator implements Generator { var statements = new ArrayList<JavaBlockStatement>(); statements.addAll(generateEncode( + // The size of the list is an int, so casting to a long is safe. new JavaCast(JavaTypeRef.LONG, new JavaMethodCall( value, JavaIdentifier.of("size"), @@ -1069,6 +1079,8 @@ public class JavaTransient0Generator implements Generator { JavaIdentifier.of("put"), List.of( this.taggedSharedValue(value, type), + // The size of the shared values map is an + // int, so casting to a long is safe. new JavaCast(JavaTypeRef.LONG, new JavaMethodCall( new JavaRef(SHARED_VALUES_NAME), JavaIdentifier.of("size"), |
