From d349b10d84d6b417171e9af3c5ae85691df4f9ff Mon Sep 17 00:00:00 2001 From: Zsombor Gegesy Date: Wed, 15 May 2024 22:28:41 +0200 Subject: [PATCH] Implement Objects.checkFromIndexSize --- src/main/java/com/github/luben/zstd/Objects.java | 13 +++++++++++++ .../java/com/github/luben/zstd/ZstdCompressCtx.java | 1 - .../com/github/luben/zstd/ZstdDecompressCtx.java | 1 - 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/github/luben/zstd/Objects.java diff --git a/src/main/java/com/github/luben/zstd/Objects.java b/src/main/java/com/github/luben/zstd/Objects.java new file mode 100644 index 0000000..482fec3 --- /dev/null +++ b/src/main/java/com/github/luben/zstd/Objects.java @@ -0,0 +1,13 @@ +package com.github.luben.zstd; + +final class Objects { + + /** + * Checks constraints, that the fromIndex, size, length is not negative, and fromIndex + size is not greater than the size. + */ + static void checkFromIndexSize(int fromIndex, int size, int length) { + if ((length | fromIndex | size) < 0 || size > length - fromIndex) { + throw new IndexOutOfBoundsException(String.format("Range [%s, %