Skip to content

Commit 6719682

Browse files
committed
Use Integer.BYTES
1 parent 8473923 commit 6719682

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/EmulatedPosixSupport.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,23 +2674,24 @@ public void setsockopt(int sockfd, int level, int optname, byte[] optval, int op
26742674
}
26752675
}
26762676

2677-
private static int encodeIntOptVal(byte[] optval, int optlen, int value) throws PosixException {
2678-
if (optlen < 4) {
2679-
byte[] tmp = new byte[4];
2677+
private static int encodeIntOptVal(byte[] optval, int optlen, int value) {
2678+
if (optlen < Integer.BYTES) {
2679+
byte[] tmp = new byte[Integer.BYTES];
26802680
nativeByteArraySupport().putInt(tmp, 0, value);
26812681
PythonUtils.arraycopy(tmp, 0, optval, 0, optlen);
26822682
} else {
26832683
nativeByteArraySupport().putInt(optval, 0, value);
26842684
}
2685-
return 4;
2685+
return Integer.BYTES;
26862686
}
26872687

2688-
private static int encodeBooleanOptVal(byte[] optval, int optlen, boolean value) throws PosixException {
2688+
private static int encodeBooleanOptVal(byte[] optval, int optlen, boolean value) {
26892689
return encodeIntOptVal(optval, optlen, value ? 1 : 0);
26902690
}
26912691

26922692
private static int decodeIntOptVal(byte[] optval, int optlen) throws PosixException {
2693-
if (optlen != 4 || optval.length < 4) {
2693+
assert optval.length >= optlen;
2694+
if (optlen != Integer.BYTES) {
26942695
throw posixException(OSErrorEnum.EINVAL);
26952696
}
26962697
return nativeByteArraySupport().getInt(optval, 0);

0 commit comments

Comments
 (0)