about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorRory Bradford <roryrjb@gmail.com>2019-12-22 09:36:50 +0000
committerRory Bradford <roryrjb@gmail.com>2019-12-22 09:36:50 +0000
commitb5d38bf5fd730dac90455d66d9b2696e9ef8ac0e (patch)
treefb426ba5aa185a4cceff51a19f8ff0b43764741a
parentd76a0fc9922bf35f879a73081d1291292c64331a (diff)
downloadrf-b5d38bf5fd730dac90455d66d9b2696e9ef8ac0e.tar.gz
Fix uninitialised variables
Signed-off-by: Rory Bradford <roryrjb@gmail.com>
-rw-r--r--rf.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/rf.c b/rf.c
index 81a90e6..dbd254a 100644
--- a/rf.c
+++ b/rf.c
@@ -191,6 +191,7 @@ static int recurse_find(char **patterns, int *pattern_count, char *dirname,
 					char last =
 						pattern[strlen(pattern) - 1];
 					char *parsed = NULL;
+					int arg_len = strlen(pattern);
 
 					if (last == '$' && first == '^') {
 						/* show everything */
@@ -210,19 +211,31 @@ static int recurse_find(char **patterns, int *pattern_count, char *dirname,
 					} else if (last == '$') {
 						/* match at end */
 						parsed =
-							strslice(pattern, 0, 1);
+							arg_len == 1 ?
+								NULL :
+								strslice(
+									pattern,
+									0, 1);
 
 						if (at_side(0, entry->d_name,
-							    parsed)) {
+							    arg_len == 1 ?
+								    pattern :
+								    parsed)) {
 							matched = 1;
 						}
 					} else if (first == '^') {
 						/* match at beginning */
 						parsed =
-							strslice(pattern, 1, 0);
+							arg_len == 1 ?
+								NULL :
+								strslice(
+									pattern,
+									1, 0);
 
 						if (at_side(1, entry->d_name,
-							    parsed)) {
+							    arg_len == 1 ?
+								    pattern :
+								    parsed)) {
 							matched = 1;
 						}
 					} else {
@@ -328,7 +341,7 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (optind > 0) {
+	if (optind > 1) {
 		int i = 0;
 		struct switches switches;
 		int pattern_count = optind - 1;