The open systcall is allowed to return 0 as a valid file descriptor,
and considering it an error breaks environments where unnecessary
fds are closed before executing untrusted processes.
Fixes: #199
Signed-off-by: Marc Zyngier <maz@kernel.org>
Read callback may fire itself on its own even after its been
requested to stop and exactly before the calling code
waits for its completion in indefinite loop.
Explicitly preventing re-fireing the submission loop,
fixes the issue.
Fixes: #142.
Signed-off-by: Ihor Dutchak <ihor.youw@gmail.com>
In one of the early versions of macOS, when you try to close the device
with IOHIDDeviceClose() that is being physically disconnected.
Starting with some version of macOS, this crash bug was fixed,
and starting with macSO 10.15 the opposite effect took place:
in some environments crash happens if IOHIDDeviceClose() is _not_ called.
This patch is to keep a workaround for old versions of macOS,
and don't have a leak in new/tested environments.
Fixes: #144.
- cast hidapi supplied size_t parameters to DWORD when calling Windows
API functions
- cast size_t return variables in `hid_read_timeout` and
`hid_send_feature_report` to int in order to match hidapi signature.
The compiler provided the following warning message:
```
hid.c:830:29: warning: format specifies type 'void *' but the argument has type 'IOHIDDeviceRef' (aka 'struct __IOHIDDevice *') [-Wformat-pedantic]
sprintf(str, "HIDAPI_%p", dev->device_handle);
~~ ^~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/secure/_stdio.h:47:56: note: expanded from macro 'sprintf'
__builtin___sprintf_chk (str, 0, __darwin_obsz(str), __VA_ARGS__)
```
Otherwise hidapi-testgui will be put at TestGUI.app/Contents/MacOS which
results in a malformed .app structure.
The following build combinations have been tested:
* 'make -f Makefile-manual' with libtool
* 'make -f Makefile-manual' without libtool
* './configure --enable-testgui && make'
Fixes#151
Older versions of MSVC (for example when using Visual Studio 10) don't
yet support variable declaration in the middle of blocks:
hidapi\windows\hid.c(845) : error C2275: 'BOOL' : illegal use of this type as an expression
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\windef.h(153) : see declaration of 'BOOL'
Move the declaration of res to the beginning of the function. Like in
hid_get_feature_report, only res is moved, essentially ignoring the #if
0 block (or assuming it will never be enabled).