From: Joel Holdsworth Date: Sun, 8 Apr 2012 16:19:52 +0000 (+0100) Subject: fx2lafw: Safer use of libusb_get_device_list X-Git-Tag: libsigrok-0.1.0~7 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=6fbe5e6081b0f83fa97f0097bc87a21a45c48481;p=libsigrok.git fx2lafw: Safer use of libusb_get_device_list --- diff --git a/hardware/fx2lafw/fx2lafw.c b/hardware/fx2lafw/fx2lafw.c index bce5cd08..42d994d9 100644 --- a/hardware/fx2lafw/fx2lafw.c +++ b/hardware/fx2lafw/fx2lafw.c @@ -175,8 +175,14 @@ static int fx2lafw_dev_open(int dev_index) return SR_ERR; skip = 0; - libusb_get_device_list(usb_context, &devlist); - for (i = 0; devlist[i]; i++) { + const int device_count = libusb_get_device_list(usb_context, &devlist); + if (device_count < 0) { + sr_err("fx2lafw: Failed to retrieve device list (%d)", + device_count); + return SR_ERR; + } + + for (i = 0; i < device_count; i++) { if ((ret = libusb_get_device_descriptor(devlist[i], &des))) { sr_err("fx2lafw: Failed to get device descriptor: %d.", ret);