From 6be15c9af0bd90825d9571118f24e5d5da80442b Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 28 Jan 1995 13:22:53 +0000 Subject: [PATCH] (substr): Don't allocate a byte for trailing NUL in result since the result needn't be NUL-terminated. Don't NUL terminate it. --- src/tr.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/tr.c b/src/tr.c index 03a8a29840..b1f701dbe5 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; } -- 2.47.3