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.
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);
}