Browse Source

Fix segmentation when completion is empty

git-svn-id: https://klish.googlecode.com/svn/trunk@457 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
18015b3b41
1 changed files with 7 additions and 5 deletions
  1. 7 5
      clish/shell/shell_command.c

+ 7 - 5
clish/shell/shell_command.c

@@ -126,12 +126,14 @@ void clish_shell_param_generator(clish_shell_t *this, lub_argv_t *matches,
 				char *saveptr;
 				str = clish_shell_expand(
 					clish_param__get_completion(param), SHELL_VAR_ACTION, &context);
-				for (q = strtok_r(str, " \n", &saveptr);
-					q; q = strtok_r(NULL, " \n", &saveptr)) {
-					if (q == strstr(q, text))
-						lub_argv_add(matches, q);
+				if (str) {
+					for (q = strtok_r(str, " \n", &saveptr);
+						q; q = strtok_r(NULL, " \n", &saveptr)) {
+						if (q == strstr(q, text))
+							lub_argv_add(matches, q);
+					}
+					lub_string_free(str);
 				}
-				lub_string_free(str);
 			}
 			/* The common PARAM. Let ptype do the work */
 			if ((ptype = clish_param__get_ptype(param)))