summaryrefslogtreecommitdiff
path: root/stdscan.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-06-04 11:26:59 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-06-04 11:26:59 -0700
commit88c9e1f88cd1e67ad4fb2834f3cad6160d5a3fbb (patch)
tree01b0135d5f68e2e9cb80ccdf774d9f687c33fda2 /stdscan.c
parent0eebf799db452dc1980931bd2f15efde5ecdf28c (diff)
downloadnasm-88c9e1f88cd1e67ad4fb2834f3cad6160d5a3fbb.tar.gz
nasm-88c9e1f88cd1e67ad4fb2834f3cad6160d5a3fbb.tar.bz2
nasm-88c9e1f88cd1e67ad4fb2834f3cad6160d5a3fbb.zip
Fix memory management issues with expanded %include
Ownership of the filename string was a bit fuzzy, with the result that we were freeing it even though it was retained for use by __FILE__. Clean up a number of other memory management issues with the new quoting code, and change the stdscan implementation to one pass over the string.
Diffstat (limited to 'stdscan.c')
-rw-r--r--stdscan.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/stdscan.c b/stdscan.c
index 0fdd7af..4db1368 100644
--- a/stdscan.c
+++ b/stdscan.c
@@ -47,7 +47,7 @@ static char *stdscan_copy(char *p, int len)
char *text;
text = nasm_malloc(len + 1);
- strncpy(text, p, len);
+ memcpy(text, p, len);
text[len] = '\0';
if (stdscan_templen >= stdscan_tempsize) {
@@ -176,15 +176,14 @@ int stdscan(void *private_data, struct tokenval *tv)
}
} else if (*stdscan_bufptr == '\'' || *stdscan_bufptr == '"' ||
*stdscan_bufptr == '`') {
- /* a char constant */
- char s;
+ /* a quoted string */
bool rn_warn;
- stdscan_bufptr = nasm_skip_string(tv->t_charptr = stdscan_bufptr);
- s = *stdscan_bufptr;
- tv->t_inttwo = nasm_unquote(tv->t_charptr);
- if (!s)
- return tv->t_type = TOKEN_ERRNUM; /* unmatched quotes */
- stdscan_bufptr++; /* skip over final quote */
+ char start_quote = *stdscan_bufptr;
+ tv->t_charptr = stdscan_bufptr;
+ tv->t_inttwo = nasm_unquote(tv->t_charptr, &stdscan_bufptr);
+ if (*stdscan_bufptr != start_quote)
+ return tv->t_type = TOKEN_ERRNUM;
+ stdscan_bufptr++; /* Skip final quote */
tv->t_integer = readstrnum(tv->t_charptr, tv->t_inttwo, &rn_warn);
/* Issue: can't readily check rn_warn, because we might be in
a db family context... */