OpenKinect / libfreenect

Drivers and libraries for the Xbox Kinect device on Windows, Linux, and OS X
http://openkinect.org
3.57k stars 1.15k forks source link

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

Closed kptrofatter closed 2 years ago

kptrofatter commented 2 years ago

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