ref: f88d0c372d9e23c82b6b89f85690d26959d83441
parent: 7cdd1c46c5bb29572c69cbf2dcff3fba6a4a7a1d
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Thu Mar 6 17:53:20 EST 2014
nusb: fix loaddevstr() (thanks erik quanstro and richard miller) loaddevstr() should request 256 bytes, as per standard and respect the length embedded in the string.
--- a/sys/src/cmd/nusb/lib/dev.c
+++ b/sys/src/cmd/nusb/lib/dev.c
@@ -186,18 +186,19 @@
Rune r;
char *us;
char *s;
- char *e;
+ if(n > 0 && n > b[0])
+ n = b[0];
if(n <= 2 || (n & 1) != 0)
return strdup("none");
n = (n - 2)/2;
b += 2;
us = s = emallocz(n*UTFmax+1, 0);
- e = s + n*UTFmax+1;
for(; --n >= 0; b += 2){
r = GET2(b);
- s = seprint(s, e, "%C", r);
+ s += runetochar(s, &r);
}
+ *s = 0;
return us;
}
@@ -204,7 +205,7 @@
char*
loaddevstr(Dev *d, int sid)
{
- uchar buf[128];
+ uchar buf[256];
int langid;
int type;
int nr;