aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/compat_fts.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2016-10-18 23:13:25 +0000
committerIngo Schwarze <schwarze@openbsd.org>2016-10-18 23:13:25 +0000
commit6f918b70d4fbe4fe01d50aaaf631876109db472d (patch)
tree7900bfe856947b7d6bf57042ea753159c7146318 /compat_fts.c
parent18827e71354008663dc01d487c1e621514b171e1 (diff)
downloadmandoc-6f918b70d4fbe4fe01d50aaaf631876109db472d.tar.gz
mandoc-6f918b70d4fbe4fe01d50aaaf631876109db472d.tar.zst
mandoc-6f918b70d4fbe4fe01d50aaaf631876109db472d.zip
sync with OpenBSD
Diffstat (limited to 'compat_fts.c')
-rw-r--r--compat_fts.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/compat_fts.c b/compat_fts.c
index 881a293b..65caa851 100644
--- a/compat_fts.c
+++ b/compat_fts.c
@@ -6,8 +6,8 @@ int dummy;
#else
-/* $Id: compat_fts.c,v 1.10 2016/08/02 11:09:46 schwarze Exp $ */
-/* $OpenBSD: fts.c,v 1.50 2015/01/16 16:48:51 deraadt Exp $ */
+/* $Id: compat_fts.c,v 1.11 2016/10/18 23:13:25 schwarze Exp $ */
+/* $OpenBSD: fts.c,v 1.56 2016/09/21 04:38:56 guenther Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@@ -83,7 +83,6 @@ fts_open(char * const *argv, int options, void *dummy)
FTSENT *p, *root;
int nitems;
FTSENT *parent, *tmp;
- size_t len;
/* Options check. */
if (options & ~FTS_OPTIONMASK) {
@@ -91,6 +90,12 @@ fts_open(char * const *argv, int options, void *dummy)
return (NULL);
}
+ /* At least one path must be specified. */
+ if (*argv == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
/* Allocate/initialize the stream */
if ((sp = calloc(1, sizeof(FTS))) == NULL)
return (NULL);
@@ -110,13 +115,7 @@ fts_open(char * const *argv, int options, void *dummy)
/* Allocate/initialize root(s). */
for (root = NULL, nitems = 0; *argv; ++argv, ++nitems) {
- /* Don't allow zero-length paths. */
- if ((len = strlen(*argv)) == 0) {
- errno = ENOENT;
- goto mem3;
- }
-
- if ((p = fts_alloc(sp, *argv, len)) == NULL)
+ if ((p = fts_alloc(sp, *argv, strlen(*argv))) == NULL)
goto mem3;
p->fts_level = FTS_ROOTLEVEL;
p->fts_parent = parent;
@@ -320,7 +319,6 @@ name: t = sp->fts_path + NAPPEND(p->fts_parent);
* semantics to fts using fts_set. An error return is allowed for similar
* reasons.
*/
-/* ARGSUSED */
int
fts_set(FTS *sp, FTSENT *p, int instr)
{
@@ -419,8 +417,7 @@ fts_build(FTS *sp)
* structures already allocated.
*/
mem1: saved_errno = errno;
- if (p)
- free(p);
+ free(p);
fts_lfree(head);
(void)closedir(dirp);
cur->fts_info = FTS_ERR;
@@ -600,8 +597,7 @@ fts_palloc(FTS *sp, size_t more)
*/
more += 256;
if (sp->fts_pathlen + more < sp->fts_pathlen) {
- if (sp->fts_path)
- free(sp->fts_path);
+ free(sp->fts_path);
sp->fts_path = NULL;
errno = ENAMETOOLONG;
return (1);
@@ -609,8 +605,7 @@ fts_palloc(FTS *sp, size_t more)
sp->fts_pathlen += more;
p = realloc(sp->fts_path, sp->fts_pathlen);
if (p == NULL) {
- if (sp->fts_path)
- free(sp->fts_path);
+ free(sp->fts_path);
sp->fts_path = NULL;
return (1);
}