diff options
author | Christian Groessler <chris@groessler.org> | 2006-12-08 22:15:11 +0000 |
---|---|---|
committer | Christian Groessler <chris@groessler.org> | 2006-12-08 22:15:11 +0000 |
commit | 41d3b0565dcc16df19e520ef966a49b64065d8c3 (patch) | |
tree | 8b231e7055cea8b43103a1708a86a40abf3b3c10 /gas/config/tc-z8k.c | |
parent | 0d2bd018fdae9f49842892b4ea31532b466dda75 (diff) | |
download | gdb-41d3b0565dcc16df19e520ef966a49b64065d8c3.zip gdb-41d3b0565dcc16df19e520ef966a49b64065d8c3.tar.gz gdb-41d3b0565dcc16df19e520ef966a49b64065d8c3.tar.bz2 |
* 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.
Diffstat (limited to 'gas/config/tc-z8k.c')
-rw-r--r-- | gas/config/tc-z8k.c | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/gas/config/tc-z8k.c b/gas/config/tc-z8k.c index cd6510c..e389366 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); |