Fix off-by-one.

Intentionally done in a very verbose way to make future changes
easier.
This commit is contained in:
Michael Gmelin 2022-05-17 12:37:10 +02:00 committed by Dain Nilsson
parent 1ce6df67d6
commit 952b5b568b
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8
1 changed files with 2 additions and 2 deletions

View File

@ -176,14 +176,14 @@ def get_hidraw_descriptor(path):
# Read product
buf = array("B", [0] * 129)
fcntl.ioctl(f, HIDIOCGRAWNAME_128, buf, True)
length = buf.index(0)
length = buf.index(0) + 1 # emulate ioctl return value
name = bytearray(buf[: (length - 1)]).decode("utf-8") if length > 1 else None
# Read unique ID
try:
buf = array("B", [0] * 65)
fcntl.ioctl(f, HIDIOCGRAWUNIQ_64, buf, True)
length = buf.index(0)
length = buf.index(0) + 1 # emulate ioctl return value
serial = (
bytearray(buf[: (length - 1)]).decode("utf-8") if length > 1 else None
)