From: Jim Meyering Date: Wed, 13 Jul 1994 15:45:24 +0000 (+0000) Subject: (substr): Allocate len+1 bytes (not just len) to leave room for trailing NUL. X-Git-Tag: textutils-1_12_1~656 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dd4604716868b41238af0266423edf3bd0aa56ae;p=thirdparty%2Fcoreutils.git (substr): Allocate len+1 bytes (not just len) to leave room for trailing NUL. --- 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