Mercurial > hg > index.cgi
diff lwasm/lwasm.c @ 354:433851a26794
Make base prefix sigils error out if no number following
Prefix sigils (0x, %, &, @, $) were parsing to 0 if there was no number
following the prefix. Make parsing fail if that is the case. Note that in a
couple of obscure cases, it may give "undefined symbol" rather than "bad
operand" due to some interactions with other unfortunate features of the
source format.
author | William Astle <lost@l-w.ca> |
---|---|
date | Fri, 15 May 2015 15:47:26 -0600 |
parents | 30b2bad9b5eb |
children | 433dbc18fb41 |
line wrap: on
line diff
--- a/lwasm/lwasm.c Tue Apr 14 08:57:47 2015 -0600 +++ b/lwasm/lwasm.c Fri May 15 15:47:26 2015 -0600 @@ -439,8 +439,13 @@ neg = -1; } - if (!strchr("0123456789", **p)) + if (!**p || !strchr("0123456789", **p)) + { + (*p)--; + if (neg < 0) + (*p)--; return NULL; + } while (**p && strchr("0123456789", **p)) { @@ -463,7 +468,12 @@ } if (**p != '0' && **p != '1') + { + (*p)--; + if (neg < 0) + (*p)--; return NULL; + } while (**p && (**p == '0' || **p == '1')) { @@ -484,9 +494,13 @@ neg = -1; } - if (!strchr("0123456789abcdefABCDEF", **p)) + if (!**p || !strchr("0123456789abcdefABCDEF", **p)) + { + (*p)--; + if (neg < 0) + (*p)--; return NULL; - + } while (**p && strchr("0123456789abcdefABCDEF", **p)) { v2 = toupper(**p) - '0'; @@ -504,9 +518,11 @@ int v = 0, v2; (*p)+=2; - if (!strchr("0123456789abcdefABCDEF", **p)) + if (!**p || !strchr("0123456789abcdefABCDEF", **p)) + { + (*p) -= 2; return NULL; - + } while (**p && strchr("0123456789abcdefABCDEF", **p)) { v2 = toupper(**p) - '0'; @@ -530,9 +546,14 @@ } - if (!strchr("01234567", **p)) + if (!**p || !strchr("01234567", **p)) + { + (*p)--; + if (neg < 0) + (*p)--; return NULL; - + } + while (**p && strchr("01234567", **p)) { v = v * 8 + (**p - '0');