]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(substr): Allocate len+1 bytes (not just len) to leave room for trailing NUL.
authorJim Meyering <jim@meyering.net>
Wed, 13 Jul 1994 15:45:24 +0000 (15:45 +0000)
committerJim Meyering <jim@meyering.net>
Wed, 13 Jul 1994 15:45:24 +0000 (15:45 +0000)
src/tr.c

index fe899c0fe99f61b967f5621f45d7c2186f0dc1c4..e34eae180afe699d3532ca24d478286049640fb0 100644 (file)
--- a/src/tr.c
+++ b/src/tr.c
@@ -814,7 +814,7 @@ substr (p, first_idx, last_idx)
      int last_idx;
 {
   int len = last_idx - first_idx + 1;
-  unsigned char *tmp = (unsigned char *) xmalloc (len);
+  unsigned char *tmp = (unsigned char *) xmalloc (len + 1);
 
   assert (first_idx <= last_idx);
   /* We must use bcopy or memcpy rather than strncpy