Class Checks

java.lang.Object
org.lwjgl.system.Checks

public final class Checks extends 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.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final boolean
    Runtime checks flag.
    static final boolean
    Debug mode flag.
    static final boolean
    Debug functions flag.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    check(byte[] buf, int size)
    Helper method to ensure a array has enough capacity.
    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 long
    check(int index, int length)
     
    static long
    check(long pointer)
    Ensures that the specified pointer is not NULL (0L).
    static void
    check(long[] buf, int size)
    Helper method to ensure a array has enough capacity.
    static void
    check(short[] buf, int size)
    Helper method to ensure a array has enough capacity.
    static void
    check(CharSequence text, int size)
    Helper method to ensure a CharSequence has enough characters.
    static void
    check(Object[] array, int size)
     
    static void
    check(Buffer buf, int size)
    Helper method to ensure a buffer has enough capacity.
    static void
    check(Buffer buf, long size)
     
    static void
    check(CustomBuffer<?> buf, int size)
    Helper method to ensure a CustomBuffer has enough capacity.
    static void
    check(CustomBuffer<?> buf, long size)
     
    static boolean
    checkFunctions(long... functions)
    Checks if any of the specified functions pointers is NULL.
    static boolean
    checkFunctions(FunctionProviderLocal provider, long handle, PointerBuffer caps, int[] indices, String... functions)
    Checks if all functions are available in the function provider.
    static boolean
    checkFunctions(FunctionProvider provider, long[] caps, int[] indices, String... functions)
    Checks if all functions are available in the function provider.
    static boolean
    checkFunctions(FunctionProvider provider, PointerBuffer caps, int[] indices, String... functions)
    Checks if all functions are available in the function provider.
    static void
    checkGT(Buffer buf, int size)
     
    static void
    checkGT(CustomBuffer<?> buf, int size)
     
    static void
    checkNT(float[] buf)
    Ensures that the specified array 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(long[] buf)
    Ensures that the specified array is null-terminated.
    static void
    Ensures that the specified FloatBuffer is null-terminated.
    static void
    Ensures that the specified IntBuffer is null-terminated.
    static void
    checkNT(IntBuffer buf, int terminator)
    Ensures that the specified IntBuffer is terminated with the specified terminator.
    static void
    Ensures that the specified LongBuffer is null-terminated.
    static void
    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
    Ensures that the specified ByteBuffer is null-terminated (last byte equal to 0).
    static void
    checkNT1Safe(@Nullable ByteBuffer buf)
     
    static void
    Ensures that the specified ByteBuffer is null-terminated (last 2 bytes equal to 0).
    static void
    checkNT2Safe(@Nullable ByteBuffer buf)
     
    static void
    checkNTSafe(float @Nullable [] buf)
     
    static void
    checkNTSafe(int @Nullable [] buf)
     
    static void
    checkNTSafe(int @Nullable [] buf, int terminator)
     
    static void
    checkNTSafe(long @Nullable [] buf)
     
    static void
    checkNTSafe(@Nullable FloatBuffer buf)
     
    static void
    checkNTSafe(@Nullable IntBuffer buf)
     
    static void
    checkNTSafe(@Nullable IntBuffer buf, int terminator)
     
    static void
    checkNTSafe(@Nullable LongBuffer buf)
     
    static void
    checkNTSafe(@Nullable PointerBuffer buf)
     
    static void
    checkNTSafe(@Nullable PointerBuffer buf, long terminator)
     
    static void
    checkSafe(double @Nullable [] buf, int size)
     
    static void
    checkSafe(float @Nullable [] buf, int size)
     
    static void
    checkSafe(int @Nullable [] buf, int size)
     
    static void
    checkSafe(long @Nullable [] buf, int size)
     
    static void
    checkSafe(short @Nullable [] buf, int size)
     
    static void
    checkSafe(@Nullable Buffer buf, int size)
     
    static void
    checkSafe(@Nullable Buffer buf, long size)
     
    static void
    checkSafe(@Nullable CustomBuffer<?> buf, int size)
     
    static void
    checkSafe(@Nullable CustomBuffer<?> buf, long size)
     
    static int
    lengthSafe(double @Nullable [] array)
     
    static int
    lengthSafe(float @Nullable [] array)
     
    static int
    lengthSafe(int @Nullable [] array)
     
    static int
    lengthSafe(long @Nullable [] array)
     
    static int
    lengthSafe(short @Nullable [] array)
     
    static int
    remainingSafe(@Nullable Buffer buffer)
     
    static int
    remainingSafe(@Nullable CustomBuffer<?> buffer)
     
    static boolean
    reportMissing(String api, String extension)
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • 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 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, a warning message will be output to the debug stream when LWJGL fails to retrieve a function pointer.

      Can be enabled by setting Configuration.DEBUG_FUNCTIONS to true.

  • Method Details

    • lengthSafe

      public static int lengthSafe(short @Nullable [] array)
    • lengthSafe

      public static int lengthSafe(int @Nullable [] array)
    • lengthSafe

      public static int lengthSafe(long @Nullable [] array)
    • lengthSafe

      public static int lengthSafe(float @Nullable [] array)
    • lengthSafe

      public static int lengthSafe(double @Nullable [] array)
    • remainingSafe

      public static int remainingSafe(@Nullable Buffer buffer)
    • remainingSafe

      public static int remainingSafe(@Nullable CustomBuffer<?> buffer)
    • checkFunctions

      public static boolean checkFunctions(long... functions)
      Checks if any of the specified functions pointers is NULL.
      Parameters:
      functions - the function pointers to check
      Returns:
      true if all function pointers are valid, false otherwise.
    • checkFunctions

      public static boolean checkFunctions(FunctionProvider provider, PointerBuffer caps, int[] indices, String... functions)
      Checks if all functions are available in the function provider.
      Parameters:
      provider - the function address provider
      caps - the function address buffer
      indices - the function indices
      functions - the function names
      Returns:
      true if all functions are available, false otherwise
    • checkFunctions

      public static boolean checkFunctions(FunctionProviderLocal provider, long handle, PointerBuffer caps, int[] indices, String... functions)
      Checks if all functions are available in the function provider.
      Parameters:
      provider - the function address provider
      handle - the handle to a platform/device/context
      caps - the function address buffer
      indices - the function indices
      functions - the function names
      Returns:
      true if all functions are available, false otherwise
    • checkFunctions

      public static boolean checkFunctions(FunctionProvider provider, long[] caps, int[] indices, String... functions)
      Checks if all functions are available in the function provider.
      Parameters:
      provider - the function address provider
      caps - the function address buffer
      indices - the function indices
      functions - the function names
      Returns:
      true if all functions are available, false otherwise
    • reportMissing

      public static boolean reportMissing(String api, String extension)
    • check

      public static long check(long pointer)
      Ensures that the specified pointer is not NULL (0L).
      Parameters:
      pointer - the pointer to check
      Throws:
      NullPointerException - if pointer is NULL
    • 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)
      Ensures that the specified array is null-terminated.
    • checkNT

      public static void checkNT(float[] buf)
      Ensures that the specified array is null-terminated.
    • checkNT1

      public static void checkNT1(ByteBuffer buf)
      Ensures that the specified ByteBuffer is null-terminated (last byte equal to 0).
    • checkNT2

      public static void checkNT2(ByteBuffer buf)
      Ensures that the specified ByteBuffer is null-terminated (last 2 bytes equal to 0).
    • checkNT

      public static void checkNT(IntBuffer buf)
      Ensures that the specified IntBuffer is null-terminated.
    • checkNT

      public static void checkNT(IntBuffer buf, int terminator)
      Ensures that the specified IntBuffer is terminated with the specified terminator.
    • checkNT

      public static void checkNT(LongBuffer buf)
      Ensures that the specified LongBuffer is null-terminated.
    • checkNT

      public static void checkNT(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 @Nullable [] buf)
    • checkNTSafe

      public static void checkNTSafe(int @Nullable [] buf, int terminator)
    • checkNTSafe

      public static void checkNTSafe(long @Nullable [] buf)
    • checkNTSafe

      public static void checkNTSafe(float @Nullable [] buf)
    • checkNT1Safe

      public static void checkNT1Safe(@Nullable ByteBuffer buf)
    • checkNT2Safe

      public static void checkNT2Safe(@Nullable ByteBuffer buf)
    • checkNTSafe

      public static void checkNTSafe(@Nullable IntBuffer buf)
    • checkNTSafe

      public static void checkNTSafe(@Nullable IntBuffer buf, int terminator)
    • checkNTSafe

      public static void checkNTSafe(@Nullable LongBuffer buf)
    • checkNTSafe

      public static void checkNTSafe(@Nullable FloatBuffer buf)
    • checkNTSafe

      public static void checkNTSafe(@Nullable PointerBuffer buf)
    • checkNTSafe

      public static void checkNTSafe(@Nullable PointerBuffer buf, long terminator)
    • check

      public static void check(byte[] buf, int size)
      Helper method to ensure a array has enough capacity.
      Parameters:
      buf - the array to check
      size - the minimum array capacity
      Throws:
      IllegalArgumentException - if buf.length < size
    • check

      public static void check(short[] buf, int size)
      Helper method to ensure a array has enough capacity.
      Parameters:
      buf - the array to check
      size - the minimum array capacity
      Throws:
      IllegalArgumentException - if buf.length < size
    • check

      public static void check(int[] buf, int size)
      Helper method to ensure a array has enough capacity.
      Parameters:
      buf - the array to check
      size - the minimum array capacity
      Throws:
      IllegalArgumentException - if buf.length < size
    • check

      public static void check(long[] buf, int size)
      Helper method to ensure a array has enough capacity.
      Parameters:
      buf - the array to check
      size - the minimum array capacity
      Throws:
      IllegalArgumentException - if buf.length < size
    • check

      public static void check(float[] buf, int size)
      Helper method to ensure a array has enough capacity.
      Parameters:
      buf - the array to check
      size - the minimum array capacity
      Throws:
      IllegalArgumentException - if buf.length < size
    • check

      public static void check(double[] buf, int size)
      Helper method to ensure a array has enough capacity.
      Parameters:
      buf - the array to check
      size - the minimum array capacity
      Throws:
      IllegalArgumentException - if buf.length < size
    • check

      public static void check(CharSequence text, int size)
      Helper method to ensure a CharSequence has enough characters.
      Parameters:
      text - the text to check
      size - the minimum number of characters
      Throws:
      IllegalArgumentException - if text.length() < size
    • check

      public static void check(Buffer buf, int size)
      Helper method to ensure a buffer has enough capacity.
      Parameters:
      buf - the buffer to check
      size - the minimum buffer capacity
      Throws:
      IllegalArgumentException - if buf.remaining() < size
    • check

      public static void check(Buffer buf, long size)
      See Also:
    • check

      public static void check(CustomBuffer<?> buf, int size)
      Helper method to ensure a CustomBuffer has enough capacity.
      Parameters:
      buf - the buffer to check
      size - the minimum buffer capacity
      Throws:
      IllegalArgumentException - if buf.remaining() < size
    • check

      public static void check(CustomBuffer<?> buf, long size)
      See Also:
    • checkSafe

      public static void checkSafe(short @Nullable [] buf, int size)
    • checkSafe

      public static void checkSafe(int @Nullable [] buf, int size)
    • checkSafe

      public static void checkSafe(long @Nullable [] buf, int size)
    • checkSafe

      public static void checkSafe(float @Nullable [] buf, int size)
    • checkSafe

      public static void checkSafe(double @Nullable [] buf, int size)
    • checkSafe

      public static void checkSafe(@Nullable Buffer buf, int size)
    • checkSafe

      public static void checkSafe(@Nullable Buffer buf, long size)
    • checkSafe

      public static void checkSafe(@Nullable CustomBuffer<?> buf, int size)
    • checkSafe

      public static void checkSafe(@Nullable CustomBuffer<?> buf, long size)
    • check

      public static void check(Object[] array, int size)
    • checkGT

      public static void checkGT(Buffer buf, int size)
    • checkGT

      public static void checkGT(CustomBuffer<?> buf, int size)
    • check

      public static long check(int index, int length)