Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Mar 2017 21:52:22 +0000 (UTC)
From:      Baptiste Daroussin <bapt@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r315746 - head/usr.bin/diff
Message-ID:  <201703222152.v2MLqMvU036152@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bapt
Date: Wed Mar 22 21:52:22 2017
New Revision: 315746
URL: https://svnweb.freebsd.org/changeset/base/315746

Log:
  Use strndup(3) instead of malloc + memcpy

Modified:
  head/usr.bin/diff/diff.c

Modified: head/usr.bin/diff/diff.c
==============================================================================
--- head/usr.bin/diff/diff.c	Wed Mar 22 21:45:42 2017	(r315745)
+++ head/usr.bin/diff/diff.c	Wed Mar 22 21:52:22 2017	(r315746)
@@ -351,9 +351,8 @@ read_excludes_file(char *file)
 	while ((buf = fgetln(fp, &len)) != NULL) {
 		if (buf[len - 1] == '\n')
 			len--;
-		pattern = xmalloc(len + 1);
-		memcpy(pattern, buf, len);
-		pattern[len] = '\0';
+		if ((pattern = strndup(buf, len)) == NULL)
+			err(2, "xstrndup");
 		push_excludes(pattern);
 	}
 	if (strcmp(file, "-") != 0)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201703222152.v2MLqMvU036152>