aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtests/find.test16
-rw-r--r--toys/posix/find.c3
2 files changed, 18 insertions, 1 deletions
diff --git a/tests/find.test b/tests/find.test
index 4e987b60..710684ec 100755
--- a/tests/find.test
+++ b/tests/find.test
@@ -74,4 +74,20 @@ testing "find unterminated -exec {}" \
testing "find -exec {} +" \
"find dir -type f -exec ls {} +" "dir/file\n" "" ""
+# `find . -iname` was segfaulting
+testing "find -name file" \
+ "find dir -name file" "dir/file\n" "" ""
+testing "find -name FILE" \
+ "find dir -name FILE" "" "" ""
+
+testing "find -iname file" \
+ "find dir -iname FILE" "dir/file\n" "" ""
+testing "find -iname FILE" \
+ "find dir -iname FILE" "dir/file\n" "" ""
+
+
+testing "find -name (no arguments)" \
+ "find dir -name 2>&1" "find: '-name' needs 1 arg\n" "" ""
+testing "find -iname (no arguments)" \
+ "find dir -iname 2>&1" "find: '-iname' needs 1 arg\n" "" ""
rm -rf dir
diff --git a/toys/posix/find.c b/toys/posix/find.c
index febe688b..65beeb54 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -321,7 +321,8 @@ static int do_find(struct dirtree *new)
if (new && s[i] == 'p') name = path = dirtree_path(new, 0);
if (i) {
if (check || !new) {
- name = strlower(new ? name : arg);
+ char *temp = new ? name : arg;
+ name = temp ? strlower(temp) : 0;
if (!new) {
dlist_add(&TT.argdata, name);
free(path);