add various fixes to avoid a hang and several potential assertion
failures when building with DEBUG defined git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2544 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
15
ChangeLog
15
ChangeLog
@@ -67,6 +67,14 @@ CVS code -
|
|||||||
shortcut_init()
|
shortcut_init()
|
||||||
- Move the "Refresh" and "Exit" shortcuts to the beginning of
|
- Move the "Refresh" and "Exit" shortcuts to the beginning of
|
||||||
the help browser shortcut list, for consistency. (DLR)
|
the help browser shortcut list, for consistency. (DLR)
|
||||||
|
thanks_for_all_the_fish()
|
||||||
|
- Remove free_toggles() and move its code here verbatim, as it's
|
||||||
|
only called here anyway. (David Benbennick)
|
||||||
|
- Fix the code to free all open file buffers to work properly
|
||||||
|
with the previous overhaul of the multibuffer code instead of
|
||||||
|
going into an infinite loop. (DLR)
|
||||||
|
- Add additional checks for variables' not being NULL before we
|
||||||
|
try to free them, to avoid assertion failures. (DLR)
|
||||||
- nano.c:
|
- nano.c:
|
||||||
copy_filestruct()
|
copy_filestruct()
|
||||||
- Rename variable prev to copy to avoid confusion. (DLR)
|
- Rename variable prev to copy to avoid confusion. (DLR)
|
||||||
@@ -84,6 +92,8 @@ CVS code -
|
|||||||
do_output()
|
do_output()
|
||||||
- Properly allow wrapping when we insert a tab, for consistency.
|
- Properly allow wrapping when we insert a tab, for consistency.
|
||||||
(DLR)
|
(DLR)
|
||||||
|
- Don't set current_len until after it's been asserted that both
|
||||||
|
current and current->data aren't NULL. (DLR)
|
||||||
- search.c:
|
- search.c:
|
||||||
do_gotoline()
|
do_gotoline()
|
||||||
- Properly show an error message if we try to go to line 0,
|
- Properly show an error message if we try to go to line 0,
|
||||||
@@ -99,10 +109,15 @@ CVS code -
|
|||||||
num_of_digits()
|
num_of_digits()
|
||||||
- Use a size_t instead of an int, and rename to digits(). (DLR)
|
- Use a size_t instead of an int, and rename to digits(). (DLR)
|
||||||
- winio.c:
|
- winio.c:
|
||||||
|
do_statusbar_output()
|
||||||
|
- Don't set answer_len until after it's been asserted that
|
||||||
|
answer isn't NULL. (DLR)
|
||||||
nanogetstr()
|
nanogetstr()
|
||||||
- Rename variable def to curranswer to avoid confusion. (DLR)
|
- Rename variable def to curranswer to avoid confusion. (DLR)
|
||||||
- Only declare and use the tabbed variable if DISABLE_TABCOMP
|
- Only declare and use the tabbed variable if DISABLE_TABCOMP
|
||||||
isn't defined. (DLR)
|
isn't defined. (DLR)
|
||||||
|
- Refactor to remove unneccessary variable answer_len and hence
|
||||||
|
avoid an assertion failure involving it. (DLR)
|
||||||
statusq()
|
statusq()
|
||||||
- Rename variable which_history to history_list, for
|
- Rename variable which_history to history_list, for
|
||||||
consistency. (DLR)
|
consistency. (DLR)
|
||||||
|
|||||||
@@ -713,6 +713,7 @@ openfilestruct *make_new_opennode(void)
|
|||||||
openfilestruct *newnode =
|
openfilestruct *newnode =
|
||||||
(openfilestruct *)nmalloc(sizeof(openfilestruct));
|
(openfilestruct *)nmalloc(sizeof(openfilestruct));
|
||||||
newnode->filename = NULL;
|
newnode->filename = NULL;
|
||||||
|
|
||||||
return newnode;
|
return newnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -769,7 +770,7 @@ void free_openfilestruct(openfilestruct *src)
|
|||||||
* updated. */
|
* updated. */
|
||||||
void add_open_file(bool update)
|
void add_open_file(bool update)
|
||||||
{
|
{
|
||||||
if (open_files == NULL && update)
|
if (update && open_files == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* If there are no entries in open_files, make the first one. */
|
/* If there are no entries in open_files, make the first one. */
|
||||||
|
|||||||
45
src/global.c
45
src/global.c
@@ -1130,19 +1130,6 @@ void toggle_init(void)
|
|||||||
toggle_init_one(TOGGLE_MORESPACE_KEY, N_("Use of more space for editing"),
|
toggle_init_one(TOGGLE_MORESPACE_KEY, N_("Use of more space for editing"),
|
||||||
MORE_SPACE);
|
MORE_SPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
/* Deallocate all of the toggles. */
|
|
||||||
void free_toggles(void)
|
|
||||||
{
|
|
||||||
while (toggles != NULL) {
|
|
||||||
toggle *pt = toggles; /* Think "previous toggle". */
|
|
||||||
|
|
||||||
toggles = toggles->next;
|
|
||||||
free(pt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif /* !NANO_SMALL */
|
#endif /* !NANO_SMALL */
|
||||||
|
|
||||||
/* This function is called just before calling exit(). Practically, the
|
/* This function is called just before calling exit(). Practically, the
|
||||||
@@ -1162,7 +1149,8 @@ void thanks_for_all_the_fish(void)
|
|||||||
free(quotestr);
|
free(quotestr);
|
||||||
#ifdef HAVE_REGEX_H
|
#ifdef HAVE_REGEX_H
|
||||||
regfree("ereg);
|
regfree("ereg);
|
||||||
free(quoteerr);
|
if (quoteerr != NULL)
|
||||||
|
free(quoteerr);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
@@ -1219,24 +1207,28 @@ void thanks_for_all_the_fish(void)
|
|||||||
free_shortcutage(&browser_list);
|
free_shortcutage(&browser_list);
|
||||||
free_shortcutage(&gotodir_list);
|
free_shortcutage(&gotodir_list);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
free_toggles();
|
while (toggles != NULL) {
|
||||||
#endif
|
toggle *t = toggles;
|
||||||
|
|
||||||
|
toggles = toggles->next;
|
||||||
|
free(t);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#ifdef ENABLE_MULTIBUFFER
|
#ifdef ENABLE_MULTIBUFFER
|
||||||
if (open_files != NULL) {
|
if (open_files != NULL) {
|
||||||
/* We free the memory associated with each open file. */
|
/* Free the memory associated with each open file buffer. */
|
||||||
while (open_files->prev != NULL)
|
while (open_files != open_files->prev)
|
||||||
open_files = open_files->prev;
|
open_files = open_files->prev;
|
||||||
free_openfilestruct(open_files);
|
free_openfilestruct(open_files);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
free_filestruct(fileage);
|
if (fileage != NULL)
|
||||||
|
free_filestruct(fileage);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_COLOR
|
#ifdef ENABLE_COLOR
|
||||||
free(syntaxstr);
|
if (syntaxstr != NULL)
|
||||||
|
free(syntaxstr);
|
||||||
while (syntaxes != NULL) {
|
while (syntaxes != NULL) {
|
||||||
syntaxtype *bill = syntaxes;
|
syntaxtype *bill = syntaxes;
|
||||||
|
|
||||||
@@ -1264,11 +1256,14 @@ void thanks_for_all_the_fish(void)
|
|||||||
#endif /* ENABLE_COLOR */
|
#endif /* ENABLE_COLOR */
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
/* Free the history lists. */
|
/* Free the history lists. */
|
||||||
free_filestruct(searchage);
|
if (searchage != NULL)
|
||||||
free_filestruct(replaceage);
|
free_filestruct(searchage);
|
||||||
|
if (replaceage != NULL)
|
||||||
|
free_filestruct(replaceage);
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_NANORC
|
#ifdef ENABLE_NANORC
|
||||||
free(homedir);
|
if (homedir != NULL)
|
||||||
|
free(homedir);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif /* DEBUG */
|
#endif /* DEBUG */
|
||||||
|
|||||||
@@ -3874,7 +3874,7 @@ bool do_mouse(void)
|
|||||||
* TRUE. */
|
* TRUE. */
|
||||||
void do_output(char *output, size_t output_len, bool allow_cntrls)
|
void do_output(char *output, size_t output_len, bool allow_cntrls)
|
||||||
{
|
{
|
||||||
size_t current_len = strlen(current->data), i = 0;
|
size_t current_len, i = 0;
|
||||||
bool old_constupdate = ISSET(CONSTUPDATE);
|
bool old_constupdate = ISSET(CONSTUPDATE);
|
||||||
bool do_refresh = FALSE;
|
bool do_refresh = FALSE;
|
||||||
/* Do we have to call edit_refresh(), or can we get away with
|
/* Do we have to call edit_refresh(), or can we get away with
|
||||||
@@ -3885,6 +3885,8 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
|
|||||||
|
|
||||||
assert(current != NULL && current->data != NULL);
|
assert(current != NULL && current->data != NULL);
|
||||||
|
|
||||||
|
current_len = strlen(current->data);
|
||||||
|
|
||||||
/* Turn off constant cursor position display. */
|
/* Turn off constant cursor position display. */
|
||||||
UNSET(CONSTUPDATE);
|
UNSET(CONSTUPDATE);
|
||||||
|
|
||||||
|
|||||||
@@ -329,9 +329,6 @@ size_t length_of_list(const shortcut *s);
|
|||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
void toggle_init_one(int val, const char *desc, long flag);
|
void toggle_init_one(int val, const char *desc, long flag);
|
||||||
void toggle_init(void);
|
void toggle_init(void);
|
||||||
#ifdef DEBUG
|
|
||||||
void free_toggles(void);
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
void sc_init_one(shortcut **shortcutage, int key, const char *desc,
|
void sc_init_one(shortcut **shortcutage, int key, const char *desc,
|
||||||
#ifndef DISABLE_HELP
|
#ifndef DISABLE_HELP
|
||||||
|
|||||||
17
src/winio.c
17
src/winio.c
@@ -2051,12 +2051,13 @@ void do_statusbar_verbatim_input(bool *got_enter)
|
|||||||
void do_statusbar_output(char *output, size_t output_len, bool
|
void do_statusbar_output(char *output, size_t output_len, bool
|
||||||
*got_enter, bool allow_cntrls)
|
*got_enter, bool allow_cntrls)
|
||||||
{
|
{
|
||||||
size_t answer_len = strlen(answer), i = 0;
|
size_t answer_len, i = 0;
|
||||||
char *char_buf = charalloc(mb_cur_max());
|
char *char_buf = charalloc(mb_cur_max());
|
||||||
int char_buf_len;
|
int char_buf_len;
|
||||||
|
|
||||||
assert(answer != NULL);
|
assert(answer != NULL);
|
||||||
|
|
||||||
|
answer_len = strlen(answer);
|
||||||
*got_enter = FALSE;
|
*got_enter = FALSE;
|
||||||
|
|
||||||
while (i < output_len) {
|
while (i < output_len) {
|
||||||
@@ -2483,7 +2484,7 @@ int nanogetstr(bool allow_tabs, const char *buf, const char *curranswer,
|
|||||||
&s_or_t, &ran_func, &finished, TRUE)) != NANO_CANCEL_KEY &&
|
&s_or_t, &ran_func, &finished, TRUE)) != NANO_CANCEL_KEY &&
|
||||||
kbinput != NANO_ENTER_KEY) {
|
kbinput != NANO_ENTER_KEY) {
|
||||||
|
|
||||||
assert(statusbar_x <= answer_len && answer_len == strlen(answer));
|
assert(statusbar_x <= strlen(answer));
|
||||||
|
|
||||||
#ifndef DISABLE_TABCOMP
|
#ifndef DISABLE_TABCOMP
|
||||||
if (kbinput != NANO_TAB_KEY)
|
if (kbinput != NANO_TAB_KEY)
|
||||||
@@ -2496,7 +2497,7 @@ int nanogetstr(bool allow_tabs, const char *buf, const char *curranswer,
|
|||||||
if (allow_tabs) {
|
if (allow_tabs) {
|
||||||
answer = input_tab(answer, &statusbar_x, &tabbed,
|
answer = input_tab(answer, &statusbar_x, &tabbed,
|
||||||
list);
|
list);
|
||||||
answer_len = strlen(answer);
|
statusbar_x = strlen(answer);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
@@ -2517,8 +2518,7 @@ int nanogetstr(bool allow_tabs, const char *buf, const char *curranswer,
|
|||||||
if ((history =
|
if ((history =
|
||||||
get_history_older(&history_list)) != NULL) {
|
get_history_older(&history_list)) != NULL) {
|
||||||
answer = mallocstrcpy(answer, history);
|
answer = mallocstrcpy(answer, history);
|
||||||
answer_len = strlen(answer);
|
statusbar_x = strlen(answer);
|
||||||
statusbar_x = answer_len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This key has a shortcut list entry when it's used
|
/* This key has a shortcut list entry when it's used
|
||||||
@@ -2539,8 +2539,7 @@ int nanogetstr(bool allow_tabs, const char *buf, const char *curranswer,
|
|||||||
if ((history =
|
if ((history =
|
||||||
get_history_newer(&history_list)) != NULL) {
|
get_history_newer(&history_list)) != NULL) {
|
||||||
answer = mallocstrcpy(answer, history);
|
answer = mallocstrcpy(answer, history);
|
||||||
answer_len = strlen(answer);
|
statusbar_x = strlen(answer);
|
||||||
statusbar_x = answer_len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If, after scrolling down, we're at the bottom of
|
/* If, after scrolling down, we're at the bottom of
|
||||||
@@ -2550,8 +2549,7 @@ int nanogetstr(bool allow_tabs, const char *buf, const char *curranswer,
|
|||||||
if (history_list->next == NULL &&
|
if (history_list->next == NULL &&
|
||||||
answer[0] == '\0' && magichistory != NULL) {
|
answer[0] == '\0' && magichistory != NULL) {
|
||||||
answer = mallocstrcpy(answer, magichistory);
|
answer = mallocstrcpy(answer, magichistory);
|
||||||
answer_len = strlen(answer);
|
statusbar_x = strlen(answer);
|
||||||
statusbar_x = answer_len;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -2880,6 +2878,7 @@ void bottombars(const shortcut *s)
|
|||||||
|
|
||||||
if (s == main_list) {
|
if (s == main_list) {
|
||||||
slen = MAIN_VISIBLE;
|
slen = MAIN_VISIBLE;
|
||||||
|
|
||||||
assert(slen <= length_of_list(s));
|
assert(slen <= length_of_list(s));
|
||||||
} else {
|
} else {
|
||||||
slen = length_of_list(s);
|
slen = length_of_list(s);
|
||||||
|
|||||||
Reference in New Issue
Block a user