]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(substr): Don't allocate a byte for trailing NUL in result
authorJim Meyering <jim@meyering.net>
Sat, 28 Jan 1995 13:22:53 +0000 (13:22 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 28 Jan 1995 13:22:53 +0000 (13:22 +0000)
since the result needn't be NUL-terminated.  Don't NUL terminate it.

src/tr.c

index 03a8a29840adee4a2f72bbdc6093278735f5ac37..b1f701dbe5e5ac744ed5a0e6f5da2ac5c14f73c0 100644 (file)
--- 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;
 }