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)
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to