Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: third_party/hidapi/hidapi_linux.c.patch

Issue 25666010: Adding third party library hidapi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update Linux backend Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 diff --git a/third_party/hidapi/hidapi_linux.c b/third_party/hidapi/hidapi_linux .c
2 index 39181d9..c0df76f 100644
3 --- a/third_party/hidapi/hidapi_linux.c
4 +++ b/third_party/hidapi/hidapi_linux.c
5 @@ -83,6 +83,8 @@ static __u32 kernel_version = 0;
6 static hid_device *new_hid_device(void)
7 {
8 hid_device *dev = calloc(1, sizeof(hid_device));
9 + if (dev == NULL)
10 + return NULL;
11 dev->device_handle = -1;
12 dev->blocking = 1;
13 dev->uses_numbered_reports = 0;
14 @@ -102,6 +104,8 @@ static wchar_t *utf8_to_wchar_t(const char *utf8)
15 return wcsdup(L"");
16 }
17 ret = calloc(wlen+1, sizeof(wchar_t));
18 + if (ret == NULL)
19 + return NULL;
20 mbstowcs(ret, utf8, wlen+1);
21 ret[wlen] = 0x0000;
22 }
23 @@ -124,7 +128,7 @@ static int uses_numbered_reports(__u8 *report_descriptor, __ u32 size) {
24 int data_len, key_size;
25
26 while (i < size) {
27 - int key = report_descriptor[i];
28 + __u8 key = report_descriptor[i];
29
30 /* Check for the Report ID key */
31 if (key == 0x85/*Report ID*/) {
32 @@ -267,6 +271,9 @@ static int get_device_string(hid_device *dev, enum device_st ring_id key, wchar_t
33 int bus_type;
34 size_t retm;
35
36 + serial_number_utf8 = NULL;
37 + product_name_utf8 = NULL;
38 +
39 ret = parse_uevent_info(
40 udev_device_get_sysattr_value(hid_dev, "uevent"),
41 &bus_type,
42 @@ -275,6 +282,8 @@ static int get_device_string(hid_device *dev, enum device_st ring_id key, wchar_t
43 &serial_number_utf8,
44 &product_name_utf8);
45
46 + if (!ret) goto end;
47 +
48 if (bus_type == BUS_BLUETOOTH) {
49 switch (key) {
50 case DEVICE_STRING_MANUFACTURER:
51 @@ -282,11 +291,11 @@ static int get_device_string(hid_device *dev, enum device_ string_id key, wchar_t
52 ret = 0;
53 break;
54 case DEVICE_STRING_PRODUCT:
55 - retm = mbstowcs(string, product_name_utf8, maxlen);
56 + retm = mbstowcs(string, product_name_utf8, maxlen - 1);
57 ret = (retm == (size_t)-1)? -1: 0;
58 break;
59 case DEVICE_STRING_SERIAL:
60 - retm = mbstowcs(string, serial_number_utf8, maxlen);
61 + retm = mbstowcs(string, serial_number_utf8, maxlen - 1);
62 ret = (retm == (size_t)-1)? -1: 0;
63 break;
64 case DEVICE_STRING_COUNT:
65 @@ -305,7 +314,7 @@ static int get_device_string(hid_device *dev, enum device_st ring_id key, wchar_t
66 const char *str;
67 const char *key_str = NULL;
68
69 - if (key >= 0 && key < DEVICE_STRING_COUNT) {
70 + if (key < DEVICE_STRING_COUNT) {
71 key_str = device_string_names[key];
72 } else {
73 ret = -1;
74 @@ -437,6 +446,10 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsig ned short vendor_id,
75
76 /* VID/PID match. Create the record. */
77 tmp = malloc(sizeof(struct hid_device_info));
78 + if (tmp == NULL) {
79 + goto next;
80 + }
81 +
82 if (cur_dev) {
83 cur_dev->next = tmp;
84 }
85 @@ -629,13 +642,13 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path )
86
87 /* Get Report Descriptor Size */
88 res = ioctl(dev->device_handle, HIDIOCGRDESCSIZE, &desc_size);
89 - if (res < 0)
90 + if (res < 0) {
91 perror("HIDIOCGRDESCSIZE");
92 -
93 -
94 + } else {
95 /* Get Report Descriptor */
96 rpt_desc.size = desc_size;
97 res = ioctl(dev->device_handle, HIDIOCGRDESC, &rpt_desc);
98 +
99 if (res < 0) {
100 perror("HIDIOCGRDESC");
101 } else {
102 @@ -644,6 +657,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
103 uses_numbered_reports(rpt_desc.value,
104 rpt_desc.size);
105 }
106 + }
107
108 return dev;
109 }
110 @@ -699,7 +713,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigne d char *data, size_t
111 if (bytes_read < 0 && (errno == EAGAIN || errno == EINPROGRESS))
112 bytes_read = 0;
113
114 - if (bytes_read >= 0 &&
115 + if (bytes_read > 0 &&
116 kernel_version < KERNEL_VERSION(2,6,34) &&
117 dev->uses_numbered_reports) {
118 /* Work around a kernel bug. Chop off the first byte. */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698