Subject: port-i386/14816: USB "page" data appear to be unsigned
To: None <gnats-bugs@gnats.netbsd.org>
From: Ed Gould <ed@left.wing.org>
List: netbsd-bugs
Date: 12/02/2001 18:52:57
>Number:         14816
>Category:       port-i386
>Synopsis:       USB "page" data appear to be unsigned
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-i386-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Dec 02 18:54:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Ed Gould
>Release:        30 November 2001
>Organization:
>Environment:
System: NetBSD tanker.wing.org 1.5 NetBSD 1.5 (TANKER) #1: Mon Apr 16 17:18:06 PDT 2001     ed@tanker.wing.org:/usr/src/sys/arch/i386/compile/TANKER i386


>Description:
	usbhidctl reports sign-extended page numbers for the APC Back-UPS CS.

>How-To-Repeat:
	Plug in such a unit, and run "usbhidctl -f 0 -r"

>Fix:
	This patch to libusb/parse.c appears to work. Someone else
	who knows the code better than I should vet it.

Index: parse.c
===================================================================
RCS file: /cvsroot/basesrc/lib/libusb/parse.c,v
retrieving revision 1.11
diff -u -r1.11 parse.c
--- parse.c     2000/09/24 02:19:54     1.11
+++ parse.c     2001/12/03 02:46:27
@@ -111,7 +111,7 @@
        hid_item_t *c;
        unsigned int bTag = 0, bType = 0, bSize;
        unsigned char *data;
-       int dval;
+       unsigned int dval;
        unsigned char *p;
        hid_item_t *hi;
        int i;
@@ -167,18 +167,19 @@
                s->p = p;
                /*
                 * The spec is unclear if the data is signed or unsigned.
+                * Based on the responses from an APC Back-UPS CS 500VA, it
+                * looks like unsigned is the right answer.
                 */
                switch(bSize) {
                case 0:
                        dval = 0;
                        break;
                case 1:
-                       dval = (int8_t)*data++;
+                       dval = *data++;
                        break;
                case 2:
                        dval = *data++;
                        dval |= *data++ << 8;
-                       dval = (int16_t)dval;
                        break;
                case 4:
                        dval = *data++;

>Release-Note:
>Audit-Trail:
>Unformatted: