lib/libusbhid: Fix possible left shift changes signedness bit.
This bug was reported by UBSan runs. lib/libusbhid/usage.c:247:27 lib/libusbhid/usage.c:244:28 lib/libusbhid/usage.c:235:13 Can result in left shift changes signedness bit as a side effect positive number can go negative, cast it to unsigned for the operation and silence the issue. Reviewed by: kamil@
This commit is contained in:
parent
ef659d5053
commit
f76ca3088f
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: usage.c,v 1.10 2016/01/02 21:58:10 christos Exp $ */
|
||||
/* $NetBSD: usage.c,v 1.11 2020/04/04 21:23:04 fox Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999 Lennart Augustsson <augustss@NetBSD.org>
|
||||
@ -27,7 +27,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: usage.c,v 1.10 2016/01/02 21:58:10 christos Exp $");
|
||||
__RCSID("$NetBSD: usage.c,v 1.11 2020/04/04 21:23:04 fox Exp $");
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
@ -232,7 +232,7 @@ hid_parse_usage_in_page(const char *name)
|
||||
if (strncmp(pages[k].name, name, len) == 0)
|
||||
goto found;
|
||||
if (sscanf(name, "%x:%x", &k, &j) == 2) {
|
||||
return (k << 16) | j;
|
||||
return (((uint32_t)k) << 16) | j;
|
||||
}
|
||||
return -1;
|
||||
found:
|
||||
@ -241,9 +241,9 @@ hid_parse_usage_in_page(const char *name)
|
||||
if (pages[k].page_contents[j].usage == -1) {
|
||||
if (sscanf(sep, fmtcheck(
|
||||
pages[k].page_contents[j].name, "%u"), &l) == 1) {
|
||||
return (pages[k].usage << 16) | l;
|
||||
return (((uint32_t)pages[k].usage) << 16) | l;
|
||||
}
|
||||
} else if (strcmp(pages[k].page_contents[j].name, sep) == 0)
|
||||
return (pages[k].usage << 16) | pages[k].page_contents[j].usage;
|
||||
return (((uint32_t)pages[k].usage) << 16) | pages[k].page_contents[j].usage;
|
||||
return (-1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user