From 41d3b0565dcc16df19e520ef966a49b64065d8c3 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 8 Dec 2006 22:15:11 +0000 Subject: [PATCH] * config/tc-z8k.c (whatreg): Add comment describing function. Return NULL if symbol name characters follow the register number. (parse_reg): Use NULL instead of 0 for pointer values. Stop processing if whatreg returned NULL. --- gas/ChangeLog | 7 +++++++ gas/config/tc-z8k.c | 45 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/gas/ChangeLog b/gas/ChangeLog index 2a9b0769026..fa89abe5a39 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,10 @@ +2006-12-08 Christian Groessler + + * config/tc-z8k.c (whatreg): Add comment describing function. + Return NULL if symbol name characters follow the register number. + (parse_reg): Use NULL instead of 0 for pointer values. Stop + processing if whatreg returned NULL. + 2006-12-07 Kazu Hirata * config/tc-m68k.c: Update uses of EF_M68K_*. diff --git a/gas/config/tc-z8k.c b/gas/config/tc-z8k.c index cd6510c99da..e3893668ff1 100644 --- a/gas/config/tc-z8k.c +++ b/gas/config/tc-z8k.c @@ -196,19 +196,34 @@ static int the_ctrl; static int the_flags; static int the_interrupt; +/* Determine register number. src points to the ascii number + (after "rl", "rh", "r", "rr", or "rq"). If a character + outside the set of {0,',',')','('} follows the number, + return NULL to indicate that it's not a valid register + number. */ + static char * whatreg (unsigned int *reg, char *src) { + unsigned int new_reg; + + /* src[0] is already known to be a digit. */ if (ISDIGIT (src[1])) { - *reg = (src[0] - '0') * 10 + src[1] - '0'; - return src + 2; + new_reg = (src[0] - '0') * 10 + src[1] - '0'; + src += 2; } else { - *reg = (src[0] - '0'); - return src + 1; + new_reg = (src[0] - '0'); + src += 1; } + + if (src[0] != 0 && src[0] != ',' && src[0] != '(' && src[0] != ')') + return NULL; + + *reg = new_reg; + return src; } /* Parse operands @@ -231,7 +246,7 @@ whatreg (unsigned int *reg, char *src) static char * parse_reg (char *src, int *mode, unsigned int *reg) { - char *res = 0; + char *res = NULL; char regno; /* Check for stack pointer "sp" alias. */ @@ -257,9 +272,11 @@ parse_reg (char *src, int *mode, unsigned int *reg) if (src[1] == 'r' || src[1] == 'R') { if (src[2] < '0' || src[2] > '9') - return res; /* Assume no register name but a label starting with 'rr'. */ + return NULL; /* Assume no register name but a label starting with 'rr'. */ *mode = CLASS_REG_LONG; res = whatreg (reg, src + 2); + if (res == NULL) + return NULL; /* Not a valid register name. */ regno = *reg; if (regno > 14) as_bad (_("register rr%d out of range"), regno); @@ -269,9 +286,11 @@ parse_reg (char *src, int *mode, unsigned int *reg) else if (src[1] == 'h' || src[1] == 'H') { if (src[2] < '0' || src[2] > '9') - return res; /* Assume no register name but a label starting with 'rh'. */ + return NULL; /* Assume no register name but a label starting with 'rh'. */ *mode = CLASS_REG_BYTE; res = whatreg (reg, src + 2); + if (res == NULL) + return NULL; /* Not a valid register name. */ regno = *reg; if (regno > 7) as_bad (_("register rh%d out of range"), regno); @@ -279,9 +298,11 @@ parse_reg (char *src, int *mode, unsigned int *reg) else if (src[1] == 'l' || src[1] == 'L') { if (src[2] < '0' || src[2] > '9') - return res; /* Assume no register name but a label starting with 'rl'. */ + return NULL; /* Assume no register name but a label starting with 'rl'. */ *mode = CLASS_REG_BYTE; res = whatreg (reg, src + 2); + if (res == NULL) + return NULL; /* Not a valid register name. */ regno = *reg; if (regno > 7) as_bad (_("register rl%d out of range"), regno); @@ -290,9 +311,11 @@ parse_reg (char *src, int *mode, unsigned int *reg) else if (src[1] == 'q' || src[1] == 'Q') { if (src[2] < '0' || src[2] > '9') - return res; /* Assume no register name but a label starting with 'rq'. */ + return NULL; /* Assume no register name but a label starting with 'rq'. */ *mode = CLASS_REG_QUAD; res = whatreg (reg, src + 2); + if (res == NULL) + return NULL; /* Not a valid register name. */ regno = *reg; if (regno > 12) as_bad (_("register rq%d out of range"), regno); @@ -302,9 +325,11 @@ parse_reg (char *src, int *mode, unsigned int *reg) else { if (src[1] < '0' || src[1] > '9') - return res; /* Assume no register name but a label starting with 'r'. */ + return NULL; /* Assume no register name but a label starting with 'r'. */ *mode = CLASS_REG_WORD; res = whatreg (reg, src + 1); + if (res == NULL) + return NULL; /* Not a valid register name. */ regno = *reg; if (regno > 15) as_bad (_("register r%d out of range"), regno); -- 2.30.2