Message ID | 20201226213547.175071-10-alexhenrie24@gmail.com |
---|---|
State | New |
Headers | show |
Series | None | expand |
On Sat, 26 Dec 2020 22:35:47 +0100, Alex Henrie wrote: > > Signed-off-by: Alex Henrie <alexhenrie24@gmail.com> > --- > src/conf.c | 9 +-------- > 1 file changed, 1 insertion(+), 8 deletions(-) > > diff --git a/src/conf.c b/src/conf.c > index 44d1bfde..970ad643 100644 > --- a/src/conf.c > +++ b/src/conf.c > @@ -877,16 +877,9 @@ static int get_nonwhite(input_t *input) > > static inline int get_hexachar(input_t *input) > { > - int c, num = 0; > - > + int c; > c = get_char(input); > - if (c >= '0' && c <= '9') num |= (c - '0') << 4; > - else if (c >= 'a' && c <= 'f') num |= (c - 'a') << 4; > - else if (c >= 'A' && c <= 'F') num |= (c - 'A') << 4; > c = get_char(input); > - if (c >= '0' && c <= '9') num |= (c - '0') << 0; > - else if (c >= 'a' && c <= 'f') num |= (c - 'a') << 0; > - else if (c >= 'A' && c <= 'F') num |= (c - 'A') << 0; > return c; The current code is obviously wrong and the suggested fix goes even to a wronger direction :) The function should return num instead. I wonder how this did't hit any problem, so far. Maybe 0x prefix was rarely used, fortunately. thanks, Takashi
Dne 27. 12. 20 v 9:37 Takashi Iwai napsal(a): > On Sat, 26 Dec 2020 22:35:47 +0100, > Alex Henrie wrote: >> >> Signed-off-by: Alex Henrie <alexhenrie24@gmail.com> >> --- >> src/conf.c | 9 +-------- >> 1 file changed, 1 insertion(+), 8 deletions(-) >> >> diff --git a/src/conf.c b/src/conf.c >> index 44d1bfde..970ad643 100644 >> --- a/src/conf.c >> +++ b/src/conf.c >> @@ -877,16 +877,9 @@ static int get_nonwhite(input_t *input) >> >> static inline int get_hexachar(input_t *input) >> { >> - int c, num = 0; >> - >> + int c; >> c = get_char(input); >> - if (c >= '0' && c <= '9') num |= (c - '0') << 4; >> - else if (c >= 'a' && c <= 'f') num |= (c - 'a') << 4; >> - else if (c >= 'A' && c <= 'F') num |= (c - 'A') << 4; >> c = get_char(input); >> - if (c >= '0' && c <= '9') num |= (c - '0') << 0; >> - else if (c >= 'a' && c <= 'f') num |= (c - 'a') << 0; >> - else if (c >= 'A' && c <= 'F') num |= (c - 'A') << 0; >> return c; > > The current code is obviously wrong and the suggested fix goes even to > a wronger direction :) The function should return num instead. > > I wonder how this did't hit any problem, so far. Maybe 0x prefix was > rarely used, fortunately. It's a bit recent code. I fixed the return value now. It's for \xFF not for 0xFF prefix. Thank you for your investigation, Alex. Jaroslav
On Sun, Dec 27, 2020 at 5:25 AM Jaroslav Kysela <perex@perex.cz> wrote: > > Dne 27. 12. 20 v 9:37 Takashi Iwai napsal(a): > > > > The current code is obviously wrong and the suggested fix goes even to > > a wronger direction :) The function should return num instead. > > > > I wonder how this did't hit any problem, so far. Maybe 0x prefix was > > rarely used, fortunately. > > It's a bit recent code. I fixed the return value now. It's for \xFF not for > 0xFF prefix. Thank you for your investigation, Alex. Thank you for fixing this properly! -Alex
diff --git a/src/conf.c b/src/conf.c index 44d1bfde..970ad643 100644 --- a/src/conf.c +++ b/src/conf.c @@ -877,16 +877,9 @@ static int get_nonwhite(input_t *input) static inline int get_hexachar(input_t *input) { - int c, num = 0; - + int c; c = get_char(input); - if (c >= '0' && c <= '9') num |= (c - '0') << 4; - else if (c >= 'a' && c <= 'f') num |= (c - 'a') << 4; - else if (c >= 'A' && c <= 'F') num |= (c - 'A') << 4; c = get_char(input); - if (c >= '0' && c <= '9') num |= (c - '0') << 0; - else if (c >= 'a' && c <= 'f') num |= (c - 'a') << 0; - else if (c >= 'A' && c <= 'F') num |= (c - 'A') << 0; return c; }
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com> --- src/conf.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)