Index: uspace/app/bdsh/compl.c
===================================================================
--- uspace/app/bdsh/compl.c	(revision 6045ecf952aa13d0fd20bc36b884629273254896)
+++ uspace/app/bdsh/compl.c	(revision f737c1d5a5e7b7a8af265dba32d9ba938b30c6a5)
@@ -99,5 +99,5 @@
 	tokenizer_t tok;
 	token_t tokens[WORD_MAX];
-	unsigned int current_token;
+	int current_token;
 	size_t tokens_length;
 
@@ -127,5 +127,6 @@
 	
 	/* Find the current token */
-	for (current_token = 0; current_token < tokens_length; current_token++) {
+	for (current_token = 0; current_token < (int) tokens_length;
+	    current_token++) {
 		token_t *t = &tokens[current_token];
 		size_t end = t->char_start + t->char_length;
@@ -137,6 +138,7 @@
 		}
 	}
-	
-	if (tokens[current_token].type != TOKTYPE_SPACE) {
+	if (tokens_length == 0) current_token = -1;
+	
+	if (current_token >= 0 && tokens[current_token].type != TOKTYPE_SPACE) {
 		*cstart = tokens[current_token].char_start;
 	}
@@ -154,7 +156,10 @@
 		goto error;
 	}
-
-	str_ncpy(prefix, pref_size + 1, stext +
-	    tokens[current_token].byte_start, pref_size);
+	prefix[pref_size] = 0;
+
+	if (current_token >= 0) {
+		str_ncpy(prefix, pref_size + 1, stext +
+		    tokens[current_token].byte_start, pref_size);
+	}
 
 	/*
@@ -166,5 +171,5 @@
 	/* Skip any whitespace before current token */
 	int prev_token = current_token - 1;
-	if (prev_token != -1 && tokens[prev_token].type == TOKTYPE_SPACE) {
+	if (prev_token >= 0 && tokens[prev_token].type == TOKTYPE_SPACE) {
 		prev_token--;
 	}
@@ -174,5 +179,5 @@
 	 * follows a pipe token.
 	 */
-	if (prev_token == -1 || tokens[prev_token].type == TOKTYPE_SPACE)
+	if (prev_token < 0 || tokens[prev_token].type == TOKTYPE_SPACE)
 		cs->is_command = true;
 	else
