From b373ec433b579c2e9cd250801999493239c412c1 Mon Sep 17 00:00:00 2001 From: "Sunrim KIM (keen)" <3han5chou7@gmail.com> Date: Thu, 17 Jul 2014 22:23:06 +0900 Subject: [PATCH] ensure to correctly terminate hex string with non-hex char(';') --- src/read.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/read.c b/src/read.c index 734973d8..7b059a30 100644 --- a/src/read.c +++ b/src/read.c @@ -374,10 +374,11 @@ read_pipe(pic_state *pic, struct pic_port *port, char c) case 'n': c = '\n'; break; case 'r': c = '\r'; break; 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; - while((c = (next(port))) != ';' && i < 6) - hex[i++] = c; + while((hex[i++] = (next(port))) != ';' && i < s); c = (char)strtol(hex, NULL, 16); break; }