Fix hid_get_data() for negative or 32-bit report data.
This commit is contained in:
parent
bc1f6fc421
commit
c8b0c3452c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: data.c,v 1.6 2010/05/12 18:28:20 plunky Exp $ */
|
||||
/* $NetBSD: data.c,v 1.7 2016/01/01 22:59:12 jakllsch Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999 Lennart Augustsson <augustss@NetBSD.org>
|
||||
@ -27,7 +27,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: data.c,v 1.6 2010/05/12 18:28:20 plunky Exp $");
|
||||
__RCSID("$NetBSD: data.c,v 1.7 2016/01/01 22:59:12 jakllsch Exp $");
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
@ -57,10 +57,12 @@ hid_get_data(const void *p, const hid_item_t *h)
|
||||
for (i = 0; i < end; i++)
|
||||
data |= buf[offs + i] << (i*8);
|
||||
data >>= hpos % 8;
|
||||
data &= (1 << hsize) - 1;
|
||||
if (h->logical_minimum < 0 && (data & (1<<(hsize-1)))) {
|
||||
/* Need to sign extend */
|
||||
data |= 0xffffffff & ~((1<<hsize)-1);
|
||||
if (hsize < 32) {
|
||||
data &= (1 << hsize) - 1;
|
||||
if (h->logical_minimum < 0 && (data & (1<<(hsize-1)))) {
|
||||
/* Need to sign extend */
|
||||
data |= 0xffffffff & ~((1<<hsize)-1);
|
||||
}
|
||||
}
|
||||
return (int)(data);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: t_usbhid.c,v 1.2 2016/01/01 22:47:34 jakllsch Exp $ */
|
||||
/* $NetBSD: t_usbhid.c,v 1.3 2016/01/01 22:59:12 jakllsch Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2016 Jonathan A. Kollasch
|
||||
@ -27,7 +27,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: t_usbhid.c,v 1.2 2016/01/01 22:47:34 jakllsch Exp $");
|
||||
__RCSID("$NetBSD: t_usbhid.c,v 1.3 2016/01/01 22:59:12 jakllsch Exp $");
|
||||
|
||||
#include <atf-c.h>
|
||||
|
||||
@ -326,9 +326,6 @@ ATF_TC_BODY(check_hid_get_data, tc)
|
||||
int32_t data;
|
||||
uint32_t udat;
|
||||
|
||||
atf_tc_expect_fail("all negative data doesn't work, "
|
||||
"all 32-bit data doesn't work");
|
||||
|
||||
ATF_REQUIRE((hrd = hid_use_report_desc(
|
||||
range_test_report_descriptor,
|
||||
__arraycount(range_test_report_descriptor))) != NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user