usb-device: Fix serial number string

This commit is contained in:
Pali Rohár committed 2012-09-23 13:51:29 +02:00
1 parent 863cf8134a
commit b2bd1d90c7
1 file changed
+7 -2
+7 -2
View File
@@ -22,6 +22,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <ctype.h>
#include <usb.h> #include <usb.h>
@@ -76,14 +77,16 @@ static void usb_descriptor_info_print(usb_dev_handle * udev, struct usb_device *
int ret; int ret;
int i; int i;
buf[0] = 0; memset(buf, 0, sizeof(buf));
usb_get_string_simple(udev, dev->descriptor.iProduct, buf, sizeof(buf)); usb_get_string_simple(udev, dev->descriptor.iProduct, buf, sizeof(buf));
PRINTF_LINE("USB device product string: %s", buf[0] ? buf : "(not detected)"); PRINTF_LINE("USB device product string: %s", buf[0] ? buf : "(not detected)");
PRINTF_END(); PRINTF_END();
buf[0] = 0; memset(buf, 0, sizeof(buf));
memset(buf2, 0, sizeof(buf2)); memset(buf2, 0, sizeof(buf2));
ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber, buf, sizeof(buf)); ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber, buf, sizeof(buf));
if ( ! isalnum(buf[0]) )
buf[0] = 0;
for ( i = 0; i < ret; i+=2 ) { for ( i = 0; i < ret; i+=2 ) {
sscanf(buf+i, "%2x", &x); sscanf(buf+i, "%2x", &x);
if ( x > 32 && x < 128 ) if ( x > 32 && x < 128 )
@@ -93,6 +96,8 @@ static void usb_descriptor_info_print(usb_dev_handle * udev, struct usb_device *
break; break;
} }
} }
if ( ! isalnum(buf2[0]) )
buf2[0] = 0;
PRINTF_LINE("USB device serial number string: %s", buf2[0] ? buf2 : ( buf[0] ? buf : "(not detected)" )); PRINTF_LINE("USB device serial number string: %s", buf2[0] ? buf2 : ( buf[0] ? buf : "(not detected)" ));
PRINTF_END(); PRINTF_END();