Commit Diff


commit - 6a91d28331c6c2bf720d27325d5655cfbc8b9248
commit + 33cbf02b9777cd078e8a37db5ae068465219301c
blob - c1f1819aab4eca2209fa34a6d51e81350c702c96
blob + fd052abf8a8b6704d976ad97d0b120a4dc02ad51
--- tog/tog.c
+++ tog/tog.c
@@ -1793,21 +1793,25 @@ browse_commit_tree(struct tog_view **new_view, int beg
 
 	*new_view = tree_view;
 
+	if (got_path_is_root_dir(path))
+		return NULL;
+		
 	/* Walk the path and open corresponding tree objects. */
 	p = path;
-	while (p[0] == '/')
-		p++;
 	while (*p) {
 		struct got_tree_entry *te;
 		struct got_object_id *tree_id;
 		char *te_name;
+
+		while (p[0] == '/')
+			p++;
 
 		/* Ensure the correct subtree entry is selected. */
 		slash = strchr(p, '/');
 		if (slash == NULL)
-			slash = strchr(p, '\0');
-
-		te_name = strndup(p, slash -p);
+			te_name = strdup(p);
+		else
+			te_name = strndup(p, slash - p);
 		if (te_name == NULL) {
 			err = got_error_from_errno("strndup");
 			break;