diff options
author | Jim Meyering <jim@meyering.net> | 1995-01-28 13:22:53 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1995-01-28 13:22:53 +0000 |
commit | 6be15c9af0bd90825d9571118f24e5d5da80442b (patch) | |
tree | 29f57fa6c14070128b24bc5b500a8ec12fd778a2 /src | |
parent | 7fc638a948243e72d9628759dddd9ee784645b88 (diff) | |
download | coreutils-6be15c9af0bd90825d9571118f24e5d5da80442b.tar.xz |
(substr): Don't allocate a byte for trailing NUL in result
since the result needn't be NUL-terminated. Don't NUL terminate it.
Diffstat (limited to 'src')
-rw-r--r-- | src/tr.c | 4 |
1 files changed, 1 insertions, 3 deletions
@@ -811,13 +811,11 @@ substr (p, first_idx, last_idx) int last_idx; { int len = last_idx - first_idx + 1; - unsigned char *tmp = (unsigned char *) xmalloc (len + 1); + unsigned char *tmp = (unsigned char *) xmalloc (len); assert (first_idx <= last_idx); /* Use memcpy rather than strncpy because `p' may contain zero-bytes. */ memcpy (tmp, p + first_idx, len); - /* FIXME: then why nul-terminate. */ - tmp[len] = '\0'; return tmp; } |