diff options
author | H. Peter Anvin <hpa@zytor.com> | 2008-06-14 20:53:45 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2008-06-14 20:53:45 -0700 |
commit | 2cb033e0d94a229810b110a49a5052ef1a4dc7db (patch) | |
tree | c47f829721f3ea0a8c2c794a622837132afe50b7 /strfunc.c | |
parent | 518df30308c555a8f8d7e359cb31688af0c686db (diff) | |
download | nasm-2cb033e0d94a229810b110a49a5052ef1a4dc7db.tar.gz nasm-2cb033e0d94a229810b110a49a5052ef1a4dc7db.tar.bz2 nasm-2cb033e0d94a229810b110a49a5052ef1a4dc7db.zip |
strfunc: always null-terminate the output buffer
Make sure that the buffer is always null-terminated, even though we do
have to use the length, since the string can (and often will) have
embedded nulls.
Diffstat (limited to 'strfunc.c')
-rw-r--r-- | strfunc.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -158,10 +158,13 @@ size_t string_transform(char *str, size_t len, char **out, enum strfunc func) transform_func transform = str_transforms[func]; size_t outlen; uint8_t *s = (uint8_t *)str; + char *buf; outlen = transform(s, len, NULL); if (outlen == (size_t)-1) return -1; - return transform(s, len, *out = nasm_malloc(outlen)); + *out = buf = nasm_malloc(outlen+1); + buf[outlen] = '\0'; /* Forcibly null-terminate the buffer */ + return transform(s, len, buf); } |