Skip to content

Commit 74c562e

Browse files
committed
Fix warnings: Implicit narrowing conversion in compound assignment
- (int count - int pos) here is always an int so amount is also in the int range if the above test is true. - We can safely cast and avoid static analysis warnings: "Implicit narrowing conversion in compound assignment" - https://github.com/apache/commons-io/security/code-scanning/135 - https://github.com/apache/commons-io/security/code-scanning/88
1 parent 7cfa40d commit 74c562e

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/main/java/org/apache/commons/io/input/UnsynchronizedBufferedInputStream.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,18 +397,22 @@ public long skip(final long amount) throws IOException {
397397
}
398398

399399
if (count - pos >= amount) {
400-
pos += amount;
400+
// (int count - int pos) here is always an int so amount is also in the int range if the above test is true.
401+
// We can safely cast to int and avoid static analysis warnings.
402+
pos += (int) amount;
401403
return amount;
402404
}
403-
long read = count - pos;
405+
int read = count - pos;
404406
pos = count;
405407

406408
if (markPos != IOUtils.EOF && amount <= markLimit) {
407409
if (fillBuffer(localIn, localBuf) == IOUtils.EOF) {
408410
return read;
409411
}
410412
if (count - pos >= amount - read) {
411-
pos += amount - read;
413+
// (int count - int pos) here is always an int so (amount - read) is also in the int range if the above test is true.
414+
// We can safely cast to int and avoid static analysis warnings.
415+
pos += ((int) amount) - read;
412416
return amount;
413417
}
414418
// Couldn't get all the bytes, skip what we read

0 commit comments

Comments
 (0)