From: Jim Meyering Date: Sat, 28 Jan 1995 13:22:53 +0000 (+0000) Subject: (substr): Don't allocate a byte for trailing NUL in result X-Git-Tag: textutils-1_12_1~309 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6be15c9af0bd90825d9571118f24e5d5da80442b;p=thirdparty%2Fcoreutils.git (substr): Don't allocate a byte for trailing NUL in result since the result needn't be NUL-terminated. Don't NUL terminate it. --- 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; }