The C Source, Patches and (shudder!) Bugs
-
sfstudio
- Posts: 2
- Joined: 02 Nov 2021, 11:21
Post
by sfstudio » 02 Nov 2021, 11:23
Code: Select all
--- usb_modeswitch.c 2020-07-10 20:48:03.000000000 +0500
+++ usb_modeswitch.c.my 2021-11-02 14:17:45.585189952 +0500
@@ -376,7 +376,7 @@
case 'J': ModeMap = ModeMap + HUAWEINEW_MODE; break;
case 'X': ModeMap = ModeMap + HUAWEIALT_MODE; break;
case 'S': ModeMap = ModeMap + SIERRA_MODE; break;
- case 'O': ModeMap = ModeMap + SONY_MODE; break;; break;
+ case 'O': ModeMap = ModeMap + SONY_MODE; break;
case 'B': ModeMap = ModeMap + QISDA_MODE; break;
case 'E': ModeMap = ModeMap + QUANTA_MODE; break;
case 'G': ModeMap = ModeMap + GCT_MODE; break;
@@ -1721,13 +1724,13 @@
if (!vendor || *productList == '\0')
return NULL;
- listcopy = malloc(strlen(productList)+1);
-
if (libusb_get_device_list(ctx, &devs) < 0) {
perror("Libusb failed to get USB access!");
return 0;
}
+ listcopy = malloc(strlen(productList)+1);
+
while ((dev = devs[i++]) != NULL) {
struct libusb_device_descriptor descriptor;
libusb_get_device_descriptor(dev, &descriptor);
-
LOM
- Posts: 1404
- Joined: 11 Jul 2012, 15:14
- Location: Koh Samui, TH
Post
by LOM » 02 Nov 2021, 15:47
Right, don't allocate memory until you know that you'll need it.

-
sfstudio
- Posts: 2
- Joined: 02 Nov 2021, 11:21
Post
by sfstudio » 10 Nov 2021, 22:15
Hi. Next...
In code periodic call search devices function in code
Code: Select all
dev = search_devices(&numDefaults, DefaultVendor, DefaultProductList, TargetClass,
Configuration, searchMode);
Variable dev declarated as static struct libusb_device *dev = NULL;
search_devices, in error case, must be return NULL, not 0.
Code: Select all
--- a/user/usb_modeswitch/usb_modeswitch.c
+++ b/user/usb_modeswitch/usb_modeswitch.c
@@ -1726,7 +1726,7 @@ struct libusb_device* search_devices( int *numFound, int vendor, char* productLi
.
if (libusb_get_device_list(ctx, &devs) < 0) {
perror("Libusb failed to get USB access!");
- return 0;
+ return NULL;
}
.
listcopy = malloc(strlen(productList)+1);
-
OliviaParker
- Posts: 2
- Joined: 20 Aug 2024, 08:48
Post
by OliviaParker » 20 Aug 2024, 08:52
sfstudio wrote: 10 Nov 2021, 22:15
Hi. Next...
Drift Boss 2
In code periodic call search devices function in code
Code: Select all
dev = search_devices(&numDefaults, DefaultVendor, DefaultProductList, TargetClass,
Configuration, searchMode);
Variable dev declarated as static struct libusb_device *dev = NULL;
search_devices, in error case, must be return NULL, not 0.
Code: Select all
--- a/user/usb_modeswitch/usb_modeswitch.c
+++ b/user/usb_modeswitch/usb_modeswitch.c
@@ -1726,7 +1726,7 @@ struct libusb_device* search_devices( int *numFound, int vendor, char* productLi
.
if (libusb_get_device_list(ctx, &devs) < 0) {
perror("Libusb failed to get USB access!");
- return 0;
+ return NULL;
}
.
listcopy = malloc(strlen(productList)+1);
it's more complicated than I thought