Class Checks
- java.lang.Object
-
- org.lwjgl.system.Checks
-
public final class Checks extends java.lang.Object
A class to check buffer boundaries in general. If there is insufficient space in the buffer when the call is made then a buffer overflow would otherwise occur and cause unexpected behaviour, a crash, or worse, a security risk.Internal class, don't use.
-
-
Field Summary
Fields Modifier and Type Field and Description static boolean
CHECKS
Runtime checks flag.static boolean
DEBUG
Debug mode flag.static boolean
DEBUG_FUNCTIONS
Debug functions flag.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static void
check(java.nio.Buffer buf, int size)
Helper method to ensure a buffer has enough capacity.static void
check(java.nio.Buffer buf, long size)
static void
check(byte[] buf, int size)
Helper method to ensure a array has enough capacity.static void
check(java.lang.CharSequence text, int size)
Helper method to ensure a CharSequence has enough characters.static void
check(CustomBuffer<?> buf, int size)
Helper method to ensure aCustomBuffer
has enough capacity.static void
check(CustomBuffer<?> buf, long size)
static void
check(double[] buf, int size)
Helper method to ensure a array has enough capacity.static void
check(float[] buf, int size)
Helper method to ensure a array has enough capacity.static void
check(int[] buf, int size)
Helper method to ensure a array has enough capacity.static void
check(int index, int size)
static long
check(long pointer)
Ensures that the specified pointer is notNULL
(0L).static void
check(long[] buf, int size)
Helper method to ensure a array has enough capacity.static void
check(java.lang.Object[] array, int size)
static void
check(short[] buf, int size)
Helper method to ensure a array has enough capacity.static boolean
checkFunctions(long... functions)
Checks if any of the specified functions pointers isNULL
.static void
checkGT(java.nio.Buffer buf, int size)
static void
checkGT(CustomBuffer<?> buf, int size)
static void
checkGT(StructBuffer<?,?> buf, int size)
static void
checkNT(float[] buf)
Ensures that the specified array is null-terminated.static void
checkNT(java.nio.FloatBuffer buf)
Ensures that the specified FloatBuffer is null-terminated.static void
checkNT(int[] buf)
Ensures that the specified array is null-terminated.static void
checkNT(int[] buf, int terminator)
Ensures that the specified array is terminated with the specified terminator.static void
checkNT(java.nio.IntBuffer buf)
Ensures that the specified IntBuffer is null-terminated.static void
checkNT(java.nio.IntBuffer buf, int terminator)
Ensures that the specified IntBuffer is terminated with the specified terminator.static void
checkNT(long[] buf)
Ensures that the specified array is null-terminated.static void
checkNT(java.nio.LongBuffer buf)
Ensures that the specified LongBuffer is null-terminated.static void
checkNT(PointerBuffer buf)
Ensures that the specified PointerBuffer is null-terminated.static void
checkNT(PointerBuffer buf, long terminator)
Ensures that the specified PointerBuffer is terminated with the specified terminator.static void
checkNT1(java.nio.ByteBuffer buf)
Ensures that the specified ByteBuffer is null-terminated (last byte equal to 0).static void
checkNT1Safe(java.nio.ByteBuffer buf)
static void
checkNT2(java.nio.ByteBuffer buf)
Ensures that the specified ByteBuffer is null-terminated (last 2 bytes equal to 0).static void
checkNT2Safe(java.nio.ByteBuffer buf)
static void
checkNTSafe(float[] buf)
static void
checkNTSafe(java.nio.FloatBuffer buf)
static void
checkNTSafe(int[] buf)
static void
checkNTSafe(int[] buf, int terminator)
static void
checkNTSafe(java.nio.IntBuffer buf)
static void
checkNTSafe(java.nio.IntBuffer buf, int terminator)
static void
checkNTSafe(long[] buf)
static void
checkNTSafe(java.nio.LongBuffer buf)
static void
checkNTSafe(PointerBuffer buf)
static void
checkNTSafe(PointerBuffer buf, long terminator)
static void
checkSafe(java.nio.Buffer buf, int size)
static void
checkSafe(java.nio.Buffer buf, long size)
static void
checkSafe(CustomBuffer<?> buf, int size)
static void
checkSafe(double[] buf, int size)
static void
checkSafe(float[] buf, int size)
static void
checkSafe(int[] buf, int size)
static void
checkSafe(long[] buf, int size)
static void
checkSafe(short[] buf, int size)
static int
lengthSafe(double[] array)
static int
lengthSafe(float[] array)
static int
lengthSafe(int[] array)
static int
lengthSafe(long[] array)
static int
lengthSafe(short[] array)
static int
remainingSafe(java.nio.Buffer buffer)
static int
remainingSafe(CustomBuffer<?> buffer)
-
-
-
Field Detail
-
CHECKS
Runtime checks flag.When enabled, LWJGL will perform basic checks during its operation, mainly to avoid crashes in native code. Examples of such checks are: context-specific function address validation, buffer capacity checks, null-termination checks, etc. These checks are generally low-overhead and should not have a measurable effect on performance, so its recommended to have them enabled both during development and in production releases.
If maximum performance is required, they can be disabled by setting
Configuration.DISABLE_CHECKS
to true.
-
DEBUG
Debug mode flag.When enabled, LWJGL will perform additional checks during its operation. These checks are more expensive than the ones enabled with
Checks.CHECKS
and will have a noticeable effect on performance, so they are disabled by default. Examples of such checks are: buffer object binding state check (GL), buffer capacity checks for texture images (GL & CL), etc. LWJGL will also print additional information, mainly during start-up.Can be enabled by setting
Configuration.DEBUG
to true.
-
DEBUG_FUNCTIONS
Debug functions flag.When enabled, capabilities classes will print an error message when they fail to retrieve a function pointer.
Can be enabled by setting
Configuration.DEBUG_FUNCTIONS
to true.
-
-
Method Detail
-
lengthSafe
public static int lengthSafe(short[] array)
-
lengthSafe
public static int lengthSafe(int[] array)
-
lengthSafe
public static int lengthSafe(long[] array)
-
lengthSafe
public static int lengthSafe(float[] array)
-
lengthSafe
public static int lengthSafe(double[] array)
-
remainingSafe
public static int remainingSafe(java.nio.Buffer buffer)
-
remainingSafe
public static int remainingSafe(CustomBuffer<?> buffer)
-
checkFunctions
public static boolean checkFunctions(long... functions)
Checks if any of the specified functions pointers isNULL
.- Parameters:
functions
- the function pointers to check- Returns:
- true if all function pointers are valid, false otherwise.
-
check
public static long check(long pointer)
Ensures that the specified pointer is notNULL
(0L).- Parameters:
pointer
- the pointer to check- Throws:
java.lang.NullPointerException
-
checkNT
public static void checkNT(int[] buf)
Ensures that the specified array is null-terminated.
-
checkNT
public static void checkNT(int[] buf, int terminator)
Ensures that the specified array is terminated with the specified terminator.
-
checkNT
public static void checkNT(long[] buf) public static void checkNT(float[] buf)
Ensures that the specified array is null-terminated.
-
checkNT1
public static void checkNT1(java.nio.ByteBuffer buf)
Ensures that the specified ByteBuffer is null-terminated (last byte equal to 0).
-
checkNT2
public static void checkNT2(java.nio.ByteBuffer buf)
Ensures that the specified ByteBuffer is null-terminated (last 2 bytes equal to 0).
-
checkNT
public static void checkNT(java.nio.IntBuffer buf)
Ensures that the specified IntBuffer is null-terminated.
-
checkNT
public static void checkNT(java.nio.IntBuffer buf, int terminator)
Ensures that the specified IntBuffer is terminated with the specified terminator.
-
checkNT
public static void checkNT(java.nio.LongBuffer buf)
Ensures that the specified LongBuffer is null-terminated.
-
checkNT
public static void checkNT(java.nio.FloatBuffer buf)
Ensures that the specified FloatBuffer is null-terminated.
-
checkNT
public static void checkNT(PointerBuffer buf)
Ensures that the specified PointerBuffer is null-terminated.
-
checkNT
public static void checkNT(PointerBuffer buf, long terminator)
Ensures that the specified PointerBuffer is terminated with the specified terminator.
-
checkNTSafe
public static void checkNTSafe(int[] buf)
-
checkNTSafe
public static void checkNTSafe(int[] buf, int terminator)
-
checkNTSafe
public static void checkNTSafe(long[] buf)
-
checkNTSafe
public static void checkNTSafe(float[] buf)
-
checkNT1Safe
public static void checkNT1Safe(java.nio.ByteBuffer buf)
-
checkNT2Safe
public static void checkNT2Safe(java.nio.ByteBuffer buf)
-
checkNTSafe
public static void checkNTSafe(java.nio.IntBuffer buf)
-
checkNTSafe
public static void checkNTSafe(java.nio.IntBuffer buf, int terminator)
-
checkNTSafe
public static void checkNTSafe(java.nio.LongBuffer buf)
-
checkNTSafe
public static void checkNTSafe(java.nio.FloatBuffer buf)
-
checkNTSafe
public static void checkNTSafe(PointerBuffer buf)
-
checkNTSafe
public static void checkNTSafe(PointerBuffer buf, long terminator)
-
check
public static void check(byte[] buf, int size) public static void check(short[] buf, int size) public static void check(int[] buf, int size) public static void check(long[] buf, int size) public static void check(float[] buf, int size) public static void check(double[] buf, int size)
Helper method to ensure a array has enough capacity.- Parameters:
buf
- the array to checksize
- the minimum array capacity- Throws:
java.lang.IllegalArgumentException
-
check
public static void check(java.lang.CharSequence text, int size)
Helper method to ensure a CharSequence has enough characters.- Parameters:
text
- the text to checksize
- the minimum number of characters
-
check
public static void check(java.nio.Buffer buf, int size)
Helper method to ensure a buffer has enough capacity.- Parameters:
buf
- the buffer to checksize
- the minimum buffer capacity- Throws:
java.lang.IllegalArgumentException
-
check
public static void check(java.nio.Buffer buf, long size)
- See Also:
Checks.check(Buffer, int)
-
check
public static void check(CustomBuffer<?> buf, int size)
Helper method to ensure aCustomBuffer
has enough capacity.- Parameters:
buf
- the buffer to checksize
- the minimum buffer capacity- Throws:
java.lang.IllegalArgumentException
-
check
public static void check(CustomBuffer<?> buf, long size)
- See Also:
Checks.check(CustomBuffer, int)
-
checkSafe
public static void checkSafe(short[] buf, int size)
-
checkSafe
public static void checkSafe(int[] buf, int size)
-
checkSafe
public static void checkSafe(long[] buf, int size)
-
checkSafe
public static void checkSafe(float[] buf, int size)
-
checkSafe
public static void checkSafe(double[] buf, int size)
-
checkSafe
public static void checkSafe(java.nio.Buffer buf, int size)
-
checkSafe
public static void checkSafe(java.nio.Buffer buf, long size)
-
checkSafe
public static void checkSafe(CustomBuffer<?> buf, int size)
-
check
public static void check(java.lang.Object[] array, int size)
-
checkGT
public static void checkGT(java.nio.Buffer buf, int size)
-
checkGT
public static void checkGT(CustomBuffer<?> buf, int size)
-
checkGT
public static void checkGT(StructBuffer<?,?> buf, int size)
-
check
public static void check(int index, int size)
-
-