ensure to correctly terminate hex string with non-hex char(';')
This commit is contained in:
parent
295d7fde31
commit
b373ec433b
|
@ -374,10 +374,11 @@ read_pipe(pic_state *pic, struct pic_port *port, char c)
|
||||||
case 'n': c = '\n'; break;
|
case 'n': c = '\n'; break;
|
||||||
case 'r': c = '\r'; break;
|
case 'r': c = '\r'; break;
|
||||||
case 'x':{
|
case 'x':{
|
||||||
char hex[2]; /* Currently supports only ascii chars */
|
/* Currently supports only ascii chars */
|
||||||
|
size_t s = 3; /* 2 bytes of hex + 1 byte of terminator(';')*/
|
||||||
|
char hex[s];
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
while((c = (next(port))) != ';' && i < 6)
|
while((hex[i++] = (next(port))) != ';' && i < s);
|
||||||
hex[i++] = c;
|
|
||||||
c = (char)strtol(hex, NULL, 16);
|
c = (char)strtol(hex, NULL, 16);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue