Fix assumptions of "dir.list->len == 0".

`dir.list->len` can't be zero because we're always checking it after a call to
dir_list_init(), which populated the list with "..".

Therefore any code that checks for zero is either superfluous or a bug.

As for the modifications in find.c:

  - The bug caused us not to call panel_clean_dir(), and this caused:
    - Memory leaks resulting from calling dir_list_init() without
      dir_list_clean() first.
    - The "total size" of selected files (for example) wasn't getting cleared.

  - We remove the `if (list->len != 0)` around the
    `current_panel->is_panelized = TRUE; ...` for several reasons:
    - The code isn't called anyway if no files were found.
    - Conceptually, there's no point in distinguishing an empty listing from an
      empty panelized listing.
    - It's the de-facto current behavior (as `list->len != 0` always)

Signed-off-by: Mooffie <mooffie@gmail.com>
This commit is contained in:
Mooffie 2017-03-03 15:30:19 +02:00
parent c9f058e65b
commit bb45f84071
2 changed files with 12 additions and 18 deletions

View File

@ -1754,6 +1754,7 @@ do_find (const char *start_dir, ssize_t start_dir_len, const char *ignore_dirs,
dir_list *list = &current_panel->dir;
char *name = NULL;
panel_clean_dir (current_panel);
dir_list_init (list);
for (i = 0, entry = listbox_get_first_link (find_list); entry != NULL;
@ -1803,8 +1804,6 @@ do_find (const char *start_dir, ssize_t start_dir_len, const char *ignore_dirs,
continue;
}
if (list->len == 0) /* first turn i.e clean old list */
panel_clean_dir (current_panel);
list->list[list->len].fnamelen = strlen (p);
list->list[list->len].fname = g_strndup (p, list->list[list->len].fnamelen);
list->list[list->len].f.marked = 0;
@ -1820,21 +1819,18 @@ do_find (const char *start_dir, ssize_t start_dir_len, const char *ignore_dirs,
rotate_dash (TRUE);
}
if (list->len != 0)
{
current_panel->is_panelized = TRUE;
current_panel->is_panelized = TRUE;
/* absolute path */
if (start_dir_len < 0)
{
int ret;
vfs_path_free (current_panel->cwd_vpath);
current_panel->cwd_vpath = vfs_path_from_str (PATH_SEP_STR);
ret = chdir (PATH_SEP_STR);
(void) ret;
}
panelize_save_panel (current_panel);
/* absolute path */
if (start_dir_len < 0)
{
int ret;
vfs_path_free (current_panel->cwd_vpath);
current_panel->cwd_vpath = vfs_path_from_str (PATH_SEP_STR);
ret = chdir (PATH_SEP_STR);
(void) ret;
}
panelize_save_panel (current_panel);
}
g_free (content_pattern);

View File

@ -356,9 +356,7 @@ do_external_panelize (char *command)
current_panel->is_panelized = TRUE;
if (list->len == 0)
dir_list_init (list);
else if (list->len > 1 && IS_PATH_SEP (list->list[1].fname[0]))
if (list->len > 1 && IS_PATH_SEP (list->list[1].fname[0]))
{
vfs_path_t *vpath_root;
int ret;