From e577f9bf50664f21c7fbbb77f894602348202282 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 22 Feb 2026 13:07:10 +0100 Subject: misc fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- bfind.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'bfind.c') diff --git a/bfind.c b/bfind.c index 7ca2001..60ae7c1 100644 --- a/bfind.c +++ b/bfind.c @@ -219,6 +219,7 @@ main(int argc, char *argv[]) struct stat st; dev_t start_dev = 0; /* compiler incorrectly thinks its may be uninitialised if not assigned */ size_t i; + void *new; ARGBEGIN { case '0': @@ -260,7 +261,7 @@ main(int argc, char *argv[]) else enqueue_dir(NULL); - while ((path = dequeue())) { + for (; (path = dequeue()); free(path)) { printf("%s%c", path, ending); if (stat(path, &st)) { if (errno != ENOENT && errno != ELOOP) { @@ -269,28 +270,29 @@ main(int argc, char *argv[]) } continue; } - if (S_ISDIR(st.st_mode)) { - if (!xdev && st.st_dev != start_dev) - continue; - if (hardlinks) { - for (i = 0; i < ndevices; i++) - if (devices[i].dev == st.st_dev) - break; - if (i == ndevices) { - devices = realloc(devices, (ndevices + 1) * sizeof(*devices)); - if (!devices) { - fprintf(stderr, "%s: realloc: %s\n", argv0, strerror(errno)); - status = 1; - } - memset(&devices[ndevices], 0, sizeof(*devices)); - devices[ndevices++].dev = st.st_dev; - } - if (visit_inode(&devices[i], st.st_ino)) + if (!S_ISDIR(st.st_mode)) + continue; + if (!xdev && st.st_dev != start_dev) + continue; + if (hardlinks) { + for (i = 0; i < ndevices; i++) + if (devices[i].dev == st.st_dev) + break; + if (i == ndevices) { + new = realloc(devices, (ndevices + 1) * sizeof(*devices)); + if (!new) { + fprintf(stderr, "%s: realloc: %s\n", argv0, strerror(errno)); + status = 1; continue; + } + devices = new; + memset(&devices[ndevices], 0, sizeof(*devices)); + devices[ndevices++].dev = st.st_dev; } - enqueue_dir(path); + if (visit_inode(&devices[i], st.st_ino)) + continue; } - free(path); + enqueue_dir(path); } if (fflush(stdout) || ferror(stdout) || fclose(stdout)) { -- cgit v1.2.3-70-g09d2