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
checkArray(java.lang.Object[] array, int size)
static void
checkBuffer(java.nio.Buffer buf, int size)
Helper method to ensure a buffer has enough capacity.static void
checkBuffer(java.nio.Buffer buf, long size)
static void
checkBuffer(java.lang.CharSequence text, int size)
Helper method to ensure a CharSequence has enough characters.static void
checkBuffer(double[] buf, int size)
Helper method to ensure a array has enough capacity.static void
checkBuffer(float[] buf, int size)
Helper method to ensure a array has enough capacity.static void
checkBuffer(int[] buf, int size)
Helper method to ensure a array has enough capacity.static void
checkBuffer(long[] buf, int size)
Helper method to ensure a array has enough capacity.static void
checkBuffer(PointerBuffer buf, int size)
Helper method to ensure aPointerBuffer
has enough capacity.static void
checkBuffer(PointerBuffer buf, long size)
static void
checkBuffer(short[] buf, int size)
Helper method to ensure a array has enough capacity.static void
checkBuffer(StructBuffer<?,?> buf, int size)
Helper method to ensure aStructBuffer
has enough capacity.static void
checkBuffer(StructBuffer<?,?> buf, long size)
static void
checkBufferGT(java.nio.Buffer buf, int size)
static void
checkBufferGT(PointerBuffer buf, int size)
static void
checkBufferGT(StructBuffer<?,?> buf, int size)
static long
checkFunctionAddress(long pointer)
Ensures that the specified function pointer is not-null (0L).static boolean
checkFunctions(long... functions)
Checks if any of the specified functions pointers isNULL
.static float[]
checkNT(float[] buf)
Ensures that the specified array is null-terminated.static java.nio.FloatBuffer
checkNT(java.nio.FloatBuffer buf)
Ensures that the specified FloatBuffer is null-terminated.static int[]
checkNT(int[] buf)
Ensures that the specified array is null-terminated.static int[]
checkNT(int[] buf, int terminator)
Ensures that the specified array is terminated with the specified terminator.static java.nio.IntBuffer
checkNT(java.nio.IntBuffer buf)
Ensures that the specified IntBuffer is null-terminated.static java.nio.IntBuffer
checkNT(java.nio.IntBuffer buf, int terminator)
Ensures that the specified IntBuffer is terminated with the specified terminator.static long[]
checkNT(long[] buf)
Ensures that the specified array is null-terminated.static java.nio.LongBuffer
checkNT(java.nio.LongBuffer buf)
Ensures that the specified LongBuffer is null-terminated.static PointerBuffer
checkNT(PointerBuffer buf)
Ensures that the specified PointerBuffer is null-terminated.static PointerBuffer
checkNT(PointerBuffer buf, long terminator)
Ensures that the specified PointerBuffer is terminated with the specified terminator.static java.nio.ByteBuffer
checkNT1(java.nio.ByteBuffer buf)
Ensures that the specified ByteBuffer is null-terminated (last byte equal to 0).static java.nio.ByteBuffer
checkNT2(java.nio.ByteBuffer buf)
Ensures that the specified ByteBuffer is null-terminated (last 2 bytes equal to 0).static java.nio.ByteBuffer
checkNT4(java.nio.ByteBuffer buf)
Ensures that the specified ByteBuffer is null-terminated (last 4 bytes equal to 0).static java.nio.ByteBuffer
checkNT4(java.nio.ByteBuffer buf, int terminator)
Ensures that the specified ByteBuffer is terminated with the specified terminator (last 4 bytes equal toterminator
).static java.nio.ByteBuffer
checkNT8(java.nio.ByteBuffer buf)
Ensures that the specified ByteBuffer is null-terminated (last 8 bytes equal to 0).static java.nio.ByteBuffer
checkNTP(java.nio.ByteBuffer buf)
Ensures that the specified ByteBuffer is null-terminated (last 4 or 8 bytes equal to 0).static java.nio.ByteBuffer
checkNTP(java.nio.ByteBuffer buf, long terminator)
Ensures that the specified ByteBuffer is terminated with the specified terminator (last 4 or 8 bytes equal toterminator
).static long
checkPointer(long pointer)
Ensures that the specified pointer is not-null (0L).
-
-
-
Field Detail
-
CHECKS
public static final boolean 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
public static final boolean 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
public static final boolean 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
-
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.
-
checkFunctionAddress
public static long checkFunctionAddress(long pointer)
Ensures that the specified function pointer is not-null (0L).- Parameters:
pointer
- the pointer to check- Throws:
java.lang.IllegalStateException
-
checkPointer
public static long checkPointer(long pointer)
Ensures that the specified pointer is not-null (0L).- Parameters:
pointer
- the pointer to check- Throws:
java.lang.NullPointerException
-
checkNT1
public static java.nio.ByteBuffer checkNT1(java.nio.ByteBuffer buf)
Ensures that the specified ByteBuffer is null-terminated (last byte equal to 0).
-
checkNT2
public static java.nio.ByteBuffer checkNT2(java.nio.ByteBuffer buf)
Ensures that the specified ByteBuffer is null-terminated (last 2 bytes equal to 0).
-
checkNT4
public static java.nio.ByteBuffer checkNT4(java.nio.ByteBuffer buf)
Ensures that the specified ByteBuffer is null-terminated (last 4 bytes equal to 0).
-
checkNT4
public static java.nio.ByteBuffer checkNT4(java.nio.ByteBuffer buf, int terminator)
Ensures that the specified ByteBuffer is terminated with the specified terminator (last 4 bytes equal toterminator
).
-
checkNT8
public static java.nio.ByteBuffer checkNT8(java.nio.ByteBuffer buf)
Ensures that the specified ByteBuffer is null-terminated (last 8 bytes equal to 0).
-
checkNTP
public static java.nio.ByteBuffer checkNTP(java.nio.ByteBuffer buf)
Ensures that the specified ByteBuffer is null-terminated (last 4 or 8 bytes equal to 0).
-
checkNTP
public static java.nio.ByteBuffer checkNTP(java.nio.ByteBuffer buf, long terminator)
Ensures that the specified ByteBuffer is terminated with the specified terminator (last 4 or 8 bytes equal toterminator
).
-
checkNT
public static java.nio.IntBuffer checkNT(java.nio.IntBuffer buf)
Ensures that the specified IntBuffer is null-terminated.
-
checkNT
public static int[] checkNT(int[] buf)
Ensures that the specified array is null-terminated.
-
checkNT
public static java.nio.IntBuffer checkNT(java.nio.IntBuffer buf, int terminator)
Ensures that the specified IntBuffer is terminated with the specified terminator.
-
checkNT
public static int[] checkNT(int[] buf, int terminator)
Ensures that the specified array is terminated with the specified terminator.
-
checkNT
public static java.nio.LongBuffer checkNT(java.nio.LongBuffer buf)
Ensures that the specified LongBuffer is null-terminated.
-
checkNT
public static long[] checkNT(long[] buf)
Ensures that the specified array is null-terminated.
-
checkNT
public static java.nio.FloatBuffer checkNT(java.nio.FloatBuffer buf)
Ensures that the specified FloatBuffer is null-terminated.
-
checkNT
public static float[] checkNT(float[] buf)
Ensures that the specified array is null-terminated.
-
checkNT
public static PointerBuffer checkNT(PointerBuffer buf)
Ensures that the specified PointerBuffer is null-terminated.
-
checkNT
public static PointerBuffer checkNT(PointerBuffer buf, long terminator)
Ensures that the specified PointerBuffer is terminated with the specified terminator.
-
checkBuffer
public static void checkBuffer(short[] 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
-
checkBuffer
public static void checkBuffer(int[] 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
-
checkBuffer
public static void checkBuffer(long[] 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
-
checkBuffer
public static void checkBuffer(float[] 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
-
checkBuffer
public static void checkBuffer(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
-
checkBuffer
public static void checkBuffer(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
-
checkBuffer
public static void checkBuffer(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
-
checkBuffer
public static void checkBuffer(java.nio.Buffer buf, long size)
- See Also:
Checks.checkBuffer(Buffer, int)
-
checkBuffer
public static void checkBuffer(PointerBuffer buf, int size)
Helper method to ensure aPointerBuffer
has enough capacity.- Parameters:
buf
- the buffer to checksize
- the minimum buffer capacity- Throws:
java.lang.IllegalArgumentException
-
checkBuffer
public static void checkBuffer(PointerBuffer buf, long size)
- See Also:
Checks.checkBuffer(PointerBuffer, int)
-
checkBuffer
public static void checkBuffer(StructBuffer<?,?> buf, int size)
Helper method to ensure aStructBuffer
has enough capacity.- Parameters:
buf
- the buffer to checksize
- the minimum buffer capacity- Throws:
java.lang.IllegalArgumentException
-
checkBuffer
public static void checkBuffer(StructBuffer<?,?> buf, long size)
- See Also:
Checks.checkBuffer(StructBuffer, int)
-
checkArray
public static void checkArray(java.lang.Object[] array, int size)
-
checkBufferGT
public static void checkBufferGT(java.nio.Buffer buf, int size)
-
checkBufferGT
public static void checkBufferGT(PointerBuffer buf, int size)
-
checkBufferGT
public static void checkBufferGT(StructBuffer<?,?> buf, int size)
-
-