Skip to content

Kinect serial number fallback to audio device serial number always throws warning on success. #657

Closed
@kptrofatter

Description

@kptrofatter

If a Kinect camera device does not have a serial number, a fallback is to use the audio device serial number. However the logic in the fallback for testing the success of reading the audio device is broken and throws a warning on success.

The broken test is in src/usb_lib10.c at line 229.

src/usb_lib10.c:229
res = libusb_get_string_descriptor_ascii(audio_handle, audio_desc.iSerialNumber, serial, 256);
libusb_close(audio_handle);
if (res != 0)
{
FN_WARNING("Failed to get audio serial of K4W or 1473 device: %s\n", libusb_error_name(res));
}

The function libusb_get_string_descriptor_ascii() returns an int equal to the number of characters read on success, or a LIBUSB_ERROR code on failure [1]. The LIBUSB_SUCCESS code is 0 [2]. The code is trying to test for errors by looking for nonzero values, but in this case a positive value indicates success and a negative value indicates an error (all errors are given negative enum values). Thus the above code will always throw a warning on success and print "UNKNOWN" as an error string.

[1] https://libusb.sourceforge.io/api-1.0/group__libusb__desc.html#ga240aac96d92cb9f51e3aea79a4adbf42
[2] https://libusb.sourceforge.io/api-1.0/group__libusb__misc.html#gab2323aa0f04bc22038e7e1740b2f29ef

The code should be modified to test for a positive number of characters read (reading 0 characters successfully is not really a success). All that needs to be done is to change != into <=

src/usb_lib10.c:229
res = libusb_get_string_descriptor_ascii(audio_handle, audio_desc.iSerialNumber, serial, 256);
libusb_close(audio_handle);
if (res <= 0)
{
FN_WARNING("Failed to get audio serial of K4W or 1473 device: %s\n", libusb_error_name(res));
}

Regards,
Parker

Activity

added this to the next milestone on Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @kptrofatter@piedar

        Issue actions

          Kinect serial number fallback to audio device serial number always throws warning on success. · Issue #657 · OpenKinect/libfreenect