Browse Source

Fix implementation of clish_command_choose_longest

This was not fully NULL-proof although it could be.

This now implements "choose longest or only", which is what we want.

There is no in-tree code path that triggers the NULL-problem, but it
popped up while patching other code and IMO this should be fixed.
Ingo Albrecht 3 years ago
parent
commit
b042fbad73
1 changed files with 5 additions and 2 deletions
  1. 5 2
      clish/command/command.c

+ 5 - 2
clish/command/command.c

@@ -174,9 +174,12 @@ clish_command_t *clish_command_choose_longest(clish_command_t * cmd1,
 		return cmd1;
 	} else if (len1 < len2) {
 		return cmd2;
-	} else {
-		/* let local view override */
+	} else if (cmd1) {
+		/* priority to the first one */
 		return cmd1;
+	} else {
+		/* else use the second one */
+		return cmd2;
 	}
 }