diff options
author | H. Peter Anvin (Intel) <hpa@zytor.com> | 2019-08-09 02:34:21 -0700 |
---|---|---|
committer | H. Peter Anvin (Intel) <hpa@zytor.com> | 2019-08-09 02:34:21 -0700 |
commit | 1c21a53e4ed03371df5d9f16359545862bb4820e (patch) | |
tree | 7c44b46c5a35a8bcffd1d7698aaaddce6af4d148 /nasmlib/asprintf.c | |
parent | 80ba65e830589b2b4e77112445ab03a3ce1de773 (diff) | |
download | nasm-1c21a53e4ed03371df5d9f16359545862bb4820e.tar.gz |
preproc: fix parsing of single-line macro arguments, cleanups
The single-line macro argument parsing was completely broken as a
comma would not be recognized as an argument separator.
In the process of fixing this, make a fair bit of code cleanups.
Note: reverse tokens for smacro->expansion doesn't actually make any
sense anymore, might reconsider that.
This checkin also removes the distinction between "magic" and plain
smacros; the only difference is which specific expand method is being
invoked.
Finally, extend the allocating-string functions such that *all* the
allocating string functions support querying the length of the string
a posteori.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Diffstat (limited to 'nasmlib/asprintf.c')
-rw-r--r-- | nasmlib/asprintf.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/nasmlib/asprintf.c b/nasmlib/asprintf.c index be88d491..0b8e49d8 100644 --- a/nasmlib/asprintf.c +++ b/nasmlib/asprintf.c @@ -38,16 +38,15 @@ /* * nasm_[v]asprintf() are variants of the semi-standard [v]asprintf() * functions, except that we return the pointer instead of a count. - * The size of the string (including the final NUL!) is available - * by calling nasm_aprintf_size() afterwards. + * The length of the string (with or without the final NUL) is available + * by calling nasm_last_string_{len,size}() afterwards. * * nasm_[v]axprintf() are similar, but allocates a user-defined amount * of storage before the string, and returns a pointer to the - * allocated buffer. + * allocated buffer. The size of that area is not included in the value + * returned by nasm_last_string_size(). */ -size_t _nasm_aprintf_size; - void *nasm_vaxprintf(size_t extra, const char *fmt, va_list ap) { char *strp; @@ -55,9 +54,12 @@ void *nasm_vaxprintf(size_t extra, const char *fmt, va_list ap) size_t bytes; va_copy(xap, ap); - _nasm_aprintf_size = bytes = vsnprintf(NULL, 0, fmt, xap) + 1; + bytes = vsnprintf(NULL, 0, fmt, xap) + 1; + _nasm_last_string_size = bytes; va_end(xap); + strp = nasm_malloc(extra+bytes); + memset(strp, 0, extra); vsnprintf(strp+extra, bytes, fmt, ap); return strp; } |