Crash on "Ctrl-x h" fixed.
Pavel Roskin
proski at gnu.org
Mon Jul 9 06:44:50 UTC 2001
Hello!
I've fixed another long-standing bug in MC. Adding the current directory
to the hotlist by "Ctrl-x h" caused crash if the hotlist wasn't used
before.
In fact, I have fixed two bugs. One is that "current_group" was used in
add2hotlist without proper checking. Now the hotlist is loaded if
current_group is NULL. load_hotlist() sets current_group very early,
before it calls add2hotlist(), so the recursion is harmless.
Another bug was caused be l_hotlist not being set to NULL after being
free()d instide destroy_dlg(). In fact, l_hotlist is set to NULL in
done_hotlist(), but not in hotlist_done().
I think this bug is caused by those very confusing names. I have added
comments to explain the difference between done_hotlist() and
hotlist_done() - the former is for the memory backend whereas the later is
for GUI.
This shows how important it is to comment you work and to choose meaingful
names for functions.
The compiler warning in add2hotlist(), the last one seen with -Wall for
the text edition, has turned out to be harmless. I have added
initialization for the "current" variable to eliminate it.
ChangeLog:
* hotlist.c: Add comments to avoid confusion between
done_hotlist() and hotlist_done().
(hotlist_done): Set l_hotlist to NULL.
(add2hotlist): Load hotlist if it's neither loaded nor loading.
This fixes Ctrl-x h. Fix compiler warning.
--------------------------------------
--- hotlist.c
+++ hotlist.c
@@ -664,9 +664,14 @@ static void init_movelist (int list_type
/* add listbox to the dialogs */
}
+/*
+ * Destroy the list dialog.
+ * Don't confuse with done_hotlist() for the list in memory.
+ */
static void hotlist_done (void)
{
destroy_dlg (hotlist_dlg);
+ l_hotlist = NULL;
if (0)
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
repaint_screen ();
@@ -687,8 +692,15 @@ find_group_section (struct hotlist *grp)
static struct hotlist *
add2hotlist (char *label, char *directory, enum HotListType type, int pos)
{
- struct hotlist *current;
struct hotlist *new;
+ struct hotlist *current = NULL;
+
+ /*
+ * Hotlist is neither loaded nor loading.
+ * Must be called by "Ctrl-x a" before using hotlist.
+ */
+ if (!current_group)
+ load_hotlist ();
if (l_hotlist && l_hotlist->current)
current = l_hotlist->current->data;
@@ -1569,6 +1581,10 @@ int save_hotlist (void)
return saved;
}
+/*
+ * Unload list from memory.
+ * Don't confuse with hotlist_done() for GUI.
+ */
void done_hotlist (void)
{
if (hotlist){
--------------------------------------
Regards,
Pavel Roskin
More information about the mc-devel
mailing list