summaryrefslogtreecommitdiff
path: root/src/tr.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1995-01-28 13:22:53 +0000
committerJim Meyering <jim@meyering.net>1995-01-28 13:22:53 +0000
commit6be15c9af0bd90825d9571118f24e5d5da80442b (patch)
tree29f57fa6c14070128b24bc5b500a8ec12fd778a2 /src/tr.c
parent7fc638a948243e72d9628759dddd9ee784645b88 (diff)
downloadcoreutils-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/tr.c')
-rw-r--r--src/tr.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/src/tr.c b/src/tr.c
index 03a8a2984..b1f701dbe 100644
--- a/src/tr.c
+++ b/src/tr.c
@@ -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;
}