<commit_before>/*
 * Copyright (C) 2013 <NAME> (<EMAIL>)
 * See COPYING file for copying conditions
 */

#include "InterfaceDescriptor.h"
#include "Interface.h"
#include "EndpointDescriptor.h"

jobject wrapInterfaceDescriptor(JNIEnv *env,
    const struct libusb_interface_descriptor *descriptor)
{
    WRAP_POINTER(env, descriptor, "InterfaceDescriptor",
        "interfaceDescriptorPointer");
}

jobjectArray wrapInterfaceDescriptors(JNIEnv *env, int count,
    const struct libusb_interface_descriptor *descriptors)
{
    jobjectArray array = (jobjectArray) (*env)->NewObjectArray(env, count,
        (*env)->FindClass(env, PACKAGE_DIR"/InterfaceDescriptor"), NULL);

    int i;
    for (i = 0; i < count; i++)
        (*env)->SetObjectArrayElement(env, array, i,
            wrapInterfaceDescriptor(env, &descriptors[i]));

    return array;
}

struct libusb_interface_descriptor *unwrapInterfaceDescriptor(JNIEnv *env,
    jobject obj)
{
    UNWRAP_POINTER(env, obj, struct libusb_interface_descriptor*,
        "interfaceDescriptorPointer");
}

/**
 * byte bLength()
 */
JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bLength)
(
    JNIEnv *env, jobject this
)
{
    return unwrapInterfaceDescriptor(env, this)->bLength;
}

/**
 * byte bDescriptorType()
 */
JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bDescriptorType)
(
    JNIEnv *env, jobject this
)
{
    return unwrapInterfaceDescriptor(env, this)->bDescriptorType;
}

/**
 * byte bInterfaceNumber()
 */
JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bInterfaceNumber)
(
    JNIEnv *env, jobject this
)
{
    return unwrapInterfaceDescriptor(env, this)->bInterfaceNumber;
}

/**
 * byte bAlternateSetting()
 */
JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bAlternateSetting)
(
    JNIEnv *env, jobject this
)
{
    return unwrapInterfaceDescriptor(env, this)->bAlternateSetting;
}

/**
 * byte bNumEndpoints()
 */
JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bNumEndpoints)
(
    JNIEnv *env, jobject this
)
{
    return unwrapInterfaceDescriptor(env, this)->bNumEndpoints;
}

/**
 * byte bInterfaceClass()
 */
JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bInterfaceClass)
(
    JNIEnv *env, jobject this
)
{
    return unwrapInterfaceDescriptor(env, this)->bInterfaceClass;
}

/**
 * byte bInterfaceSubClass()
 */
JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bInterfaceSubClass)
(
    JNIEnv *env, jobject this
)
{
    return unwrapInterfaceDescriptor(env, this)->bInterfaceSubClass;
}

/**
 * byte bInterfaceProtocol()
 */
JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bInterfaceProtocol)
(
    JNIEnv *env, jobject this
)
{
    return unwrapInterfaceDescriptor(env, this)->bInterfaceProtocol;
}

/**
 * byte iInterface()
 */
JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, iInterface)
(
    JNIEnv *env, jobject this
)
{
    return unwrapInterfaceDescriptor(env, this)->iInterface;
}

/**
 * EndpointDescriptor[] endpoint()
 */
JNIEXPORT jobjectArray JNICALL METHOD_NAME(InterfaceDescriptor, endpoint)
(
    JNIEnv *env, jobject this
)
{
    struct libusb_interface_descriptor *descriptor = unwrapInterfaceDescriptor(
        env, this);
    return wrapEndpointDescriptors(env, descriptor->bNumEndpoints, descriptor->endpoint);
}

/**
 * ByteBuffer extra()
 */
JNIEXPORT jobject JNICALL METHOD_NAME(InterfaceDescriptor, extra)
(
    JNIEnv *env, jobject this
)
{
    struct libusb_interface_descriptor *descriptor =
        unwrapInterfaceDescriptor(env, this);
    return (*env)->NewDirectByteBuffer(env, (void *) descriptor->extra,
        descriptor->extra_length);
}

/**
 * int extraLength()
 */
JNIEXPORT jint JNICALL METHOD_NAME(InterfaceDescriptor, extraLength)
(
    JNIEnv *env, jobject this
)
{
    return unwrapInterfaceDescriptor(env, this)->extra_length;
}<commit_msg>Fix NULL deref in InterfaceDescriptor too.<commit_after>/*
 * Copyright (C) 2013 <NAME> (<EMAIL>)
 * See COPYING file for copying conditions
 */

#include "InterfaceDescriptor.h"
#include "Interface.h"
#include "EndpointDescriptor.h"

jobject wrapInterfaceDescriptor(JNIEnv *env,
    const struct libusb_interface_descriptor *descriptor)
{
    WRAP_POINTER(env, descriptor, "InterfaceDescriptor",
        "interfaceDescriptorPointer");
}

jobjectArray wrapInterfaceDescriptors(JNIEnv *env, int count,
    const struct libusb_interface_descriptor *descriptors)
{
    jobjectArray array = (jobjectArray) (*env)->NewObjectArray(env, count,
        (*env)->FindClass(env, PACKAGE_DIR"/InterfaceDescriptor"), NULL);

    int i;
    for (i = 0; i < count; i++)
        (*env)->SetObjectArrayElement(env, array, i,
            wrapInterfaceDescriptor(env, &descriptors[i]));

    return array;
}

struct libusb_interface_descriptor *unwrapInterfaceDescriptor(JNIEnv *env,
    jobject obj)
{
    UNWRAP_POINTER(env, obj, struct libusb_interface_descriptor*,
        "interfaceDescriptorPointer");
}

/**
 * byte bLength()
 */
JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bLength)
(
    JNIEnv *env, jobject this
)
{
    struct libusb_interface_descriptor *interface =
        unwrapInterfaceDescriptor(env, this);
    if (!interface) return 0;

    return interface->bLength;
}

/**
 * byte bDescriptorType()
 */
JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bDescriptorType)
(
    JNIEnv *env, jobject this
)
{
    struct libusb_interface_descriptor *interface =
        unwrapInterfaceDescriptor(env, this);
    if (!interface) return 0;

    return interface->bDescriptorType;
}

/**
 * byte bInterfaceNumber()
 */
JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bInterfaceNumber)
(
    JNIEnv *env, jobject this
)
{
    struct libusb_interface_descriptor *interface =
        unwrapInterfaceDescriptor(env, this);
    if (!interface) return 0;

    return interface->bInterfaceNumber;
}

/**
 * byte bAlternateSetting()
 */
JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bAlternateSetting)
(
    JNIEnv *env, jobject this
)
{
    struct libusb_interface_descriptor *interface =
        unwrapInterfaceDescriptor(env, this);
    if (!interface) return 0;

    return interface->bAlternateSetting;
}

/**
 * byte bNumEndpoints()
 */
JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bNumEndpoints)
(
    JNIEnv *env, jobject this
)
{
    struct libusb_interface_descriptor *interface =
        unwrapInterfaceDescriptor(env, this);
    if (!interface) return 0;

    return interface->bNumEndpoints;
}

/**
 * byte bInterfaceClass()
 */
JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bInterfaceClass)
(
    JNIEnv *env, jobject this
)
{
    struct libusb_interface_descriptor *interface =
        unwrapInterfaceDescriptor(env, this);
    if (!interface) return 0;

    return interface->bInterfaceClass;
}

/**
 * byte bInterfaceSubClass()
 */
JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bInterfaceSubClass)
(
    JNIEnv *env, jobject this
)
{
    struct libusb_interface_descriptor *interface =
        unwrapInterfaceDescriptor(env, this);
    if (!interface) return 0;

    return interface->bInterfaceSubClass;
}

/**
 * byte bInterfaceProtocol()
 */
JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bInterfaceProtocol)
(
    JNIEnv *env, jobject this
)
{
    struct libusb_interface_descriptor *interface =
        unwrapInterfaceDescriptor(env, this);
    if (!interface) return 0;

    return interface->bInterfaceProtocol;
}

/**
 * byte iInterface()
 */
JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, iInterface)
(
    JNIEnv *env, jobject this
)
{
    struct libusb_interface_descriptor *interface =
        unwrapInterfaceDescriptor(env, this);
    if (!interface) return 0;

    return interface->iInterface;
}

/**
 * EndpointDescriptor[] endpoint()
 */
JNIEXPORT jobjectArray JNICALL METHOD_NAME(InterfaceDescriptor, endpoint)
(
    JNIEnv *env, jobject this
)
{
    struct libusb_interface_descriptor *interface =
        unwrapInterfaceDescriptor(env, this);
    if (!interface) return NULL;

    return wrapEndpointDescriptors(env, interface->bNumEndpoints,
        interface->endpoint);
}

/**
 * ByteBuffer extra()
 */
JNIEXPORT jobject JNICALL METHOD_NAME(InterfaceDescriptor, extra)
(
    JNIEnv *env, jobject this
)
{
    struct libusb_interface_descriptor *interface =
        unwrapInterfaceDescriptor(env, this);
    if (!interface) return NULL;

    return (*env)->NewDirectByteBuffer(env, (void *) interface->extra,
        interface->extra_length);
}

/**
 * int extraLength()
 */
JNIEXPORT jint JNICALL METHOD_NAME(InterfaceDescriptor, extraLength)
(
    JNIEnv *env, jobject this
)
{
    struct libusb_interface_descriptor *interface =
        unwrapInterfaceDescriptor(env, this);
    if (!interface) return 0;

    return interface->extra_length;
}
{'fraction_non_alphanumeric': 0.10565138447571494, 'fraction_numerical': 0.0022696323195642307, 'mean_word_length': 4.515018773466833, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4537444', 'n_tokens_mistral': 2769, 'n_tokens_neox': 2656, 'n_words': 600}