When computing the length of an octal escape, we need to do an
unsigned compare, otherwise we only allocate space for one character
for bytes in the \200..\377 range, which is obviously incorrect.
Reported-by: Ed Beroset <beroset@mindspring.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
There is no point in using sprintf(), and it adds the possibility of
either bugs due to the output not matching what the byte count loop is
expecting, or just cause people to freak out due to the notion that
"sprinf is unsafe".
Reported-by: Ed Beroset <beroset@mindspring.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Add copyright headers to the *.c/*.h files in the main directory. For
files where I'm sure enough that we have all the approvals, I have
given them the 2-BSD license, the others have been given the "LGPL for
now" license header. Most of them can probably be changed after
auditing.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
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.
Semi-arbitrary change of the definition of escp to the beginning of
the argument sequence instead of the initiator character. This may
avoid an add in some code paths, and looks slightly cleaner to me.
We used numbers in nasm_unquote and C escapes in nasm_quote - use
numbers in both places, just in case some C compiler does something
weird with '\r' and (especially) '\n'.
Make the code a bit more consistent:
- ndig is now always a countdown, and we always to the (p > escp+1)
test to see if we got anything at all (this is to deal with stuff
like \x without a digit.)
- Add missing break; after 'v' (bug!).
- Preinitialize nval to zero.
Greatly simplify nasm_skip_string() by observing that for the purpose
of string skipping, all states other than st_backslash are equivalent
to st_start.