From dd4604716868b41238af0266423edf3bd0aa56ae Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 13 Jul 1994 15:45:24 +0000 Subject: [PATCH] (substr): Allocate len+1 bytes (not just len) to leave room for trailing NUL. --- src/tr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tr.c b/src/tr.c index fe899c0fe9..e34eae180a 100644 --- 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 -- 2.47.3