Fix CodeQL warnings (#4348)

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich 2024-08-17 14:57:45 +02:00 committed by GitHub
parent 76597838c4
commit 0e1883bdae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 12 additions and 7 deletions

View File

@ -139,7 +139,7 @@ public class Audio {
if (newVolume - volume < .01) { if (newVolume - volume < .01) {
// the getMasterVolume() may only returns integers, so we have to make sure that we // the getMasterVolume() may only returns integers, so we have to make sure that we
// increase the volume level at least by 1%. // increase the volume level at least by 1%.
newVolume += .01; newVolume += .01f;
} }
if (newVolume > 1) { if (newVolume > 1) {
newVolume = 1; newVolume = 1;

View File

@ -145,7 +145,7 @@ public class JavaTest {
* @return true on success, false on timeout * @return true on success, false on timeout
*/ */
protected boolean waitFor(BooleanSupplier condition, long timeout, long sleepTime) { protected boolean waitFor(BooleanSupplier condition, long timeout, long sleepTime) {
int waitingTime = 0; long waitingTime = 0;
boolean rv; boolean rv;
while (!(rv = condition.getAsBoolean()) && waitingTime < timeout) { while (!(rv = condition.getAsBoolean()) && waitingTime < timeout) {
waitingTime += sleepTime; waitingTime += sleepTime;

View File

@ -89,7 +89,10 @@ public class InputStreamCacheWrapper extends InputStream {
@Override @Override
public long skip(long n) throws IOException { public long skip(long n) throws IOException {
offset += n; if (n > Integer.MAX_VALUE || n < Integer.MIN_VALUE) {
throw new IOException("Invalid offset, exceeds Integer range");
}
offset += (int) n;
return n; return n;
} }
@ -103,7 +106,7 @@ public class InputStreamCacheWrapper extends InputStream {
} }
public long length() { public long length() {
Long totalSize = cacheEntry.getTotalSize(); long totalSize = cacheEntry.getTotalSize();
if (totalSize > 0L) { if (totalSize > 0L) {
return totalSize; return totalSize;
} }

View File

@ -127,7 +127,7 @@ public class LRUMediaCacheEntry<V> {
* *
* @return * @return
*/ */
protected Long getTotalSize() { protected long getTotalSize() {
if (completed) { // we already know the total size of the sound if (completed) { // we already know the total size of the sound
return currentSize; return currentSize;
} else { } else {
@ -323,7 +323,9 @@ public class LRUMediaCacheEntry<V> {
return 0; return 0;
} }
try { try {
return Math.max(0, Long.valueOf(fileChannelLocal.size() - offset).intValue()); long nBytes = Math.min(Integer.MAX_VALUE, Math.max(0, fileChannelLocal.size() - offset));
// nBytes is for sure in integer range, safe to cast
return (int) nBytes;
} catch (IOException e) { } catch (IOException e) {
logger.debug("Cannot get file length for cache file {}", key); logger.debug("Cannot get file length for cache file {}", key);
return 0; return 0;

View File

@ -52,7 +52,7 @@ public class JavaTest {
* @return true on success, false on timeout * @return true on success, false on timeout
*/ */
protected boolean waitFor(BooleanSupplier condition, long timeout, long sleepTime) { protected boolean waitFor(BooleanSupplier condition, long timeout, long sleepTime) {
int waitingTime = 0; long waitingTime = 0;
boolean rv; boolean rv;
while (!(rv = condition.getAsBoolean()) && waitingTime < timeout) { while (!(rv = condition.getAsBoolean()) && waitingTime < timeout) {
waitingTime += sleepTime; waitingTime += sleepTime;