libftdi Archives

Subject: Feature Request: Identify LibFTDI Device Strings

From: Karl Semich <0xloem@xxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Wed, 10 Feb 2021 17:21:37 -0500
Hi,

I've been calling ftdi_usb_open_string() simply for the purpose of
validating device strings for use later, and then discarding my
context.

Unfortunately, sometimes the call to libusb_init() fails and ftdi_new
then returns 0.  When this happens, it is hard to find a way to
reliably validate one of these strings.  ftdi_usb_open_string() is
documented as possibly changing what strings it accepts in the future,
so doing the validation by hand is unideal.

It seems ftdi_usb_open_string() returns -12 if the ftdi pointer is
null, _before_ it validates the string, and contrariwise dereferences
the passed pointer if it is not null, preventing a user from fudging
validation with a fake pointer.

It would be great if this check returning -12 were simply moved after
the basic string validation, so the -11 return value could be used
even without an ftdi context.  This could probably be done robustly by
handing off the port opening to the other functions that don't take
strings, after the string has been parsed.

It would alternatively be great if the string validation code were
moved into a new public function like ftdi_valid_usb_string(const char
*), so that what the user is accomplishing can be detected without
setting up all the infrastructure.

Thank you for reading.

--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread