1
1

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
Этот коммит содержится в:
David Lawrence Ramsey 2005-05-26 05:17:13 +00:00
родитель e4acb69611
Коммит 31b159c1b3
6 изменённых файлов: 48 добавлений и 39 удалений

Просмотреть файл

@ -67,6 +67,14 @@ CVS code -
shortcut_init()
- Move the "Refresh" and "Exit" shortcuts to the beginning of
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:
copy_filestruct()
- Rename variable prev to copy to avoid confusion. (DLR)
@ -84,6 +92,8 @@ CVS code -
do_output()
- Properly allow wrapping when we insert a tab, for consistency.
(DLR)
- Don't set current_len until after it's been asserted that both
current and current->data aren't NULL. (DLR)
- search.c:
do_gotoline()
- Properly show an error message if we try to go to line 0,
@ -99,10 +109,15 @@ CVS code -
num_of_digits()
- Use a size_t instead of an int, and rename to digits(). (DLR)
- winio.c:
do_statusbar_output()
- Don't set answer_len until after it's been asserted that
answer isn't NULL. (DLR)
nanogetstr()
- Rename variable def to curranswer to avoid confusion. (DLR)
- Only declare and use the tabbed variable if DISABLE_TABCOMP
isn't defined. (DLR)
- Refactor to remove unneccessary variable answer_len and hence
avoid an assertion failure involving it. (DLR)
statusq()
- Rename variable which_history to history_list, for
consistency. (DLR)

Просмотреть файл

@ -713,6 +713,7 @@ openfilestruct *make_new_opennode(void)
openfilestruct *newnode =
(openfilestruct *)nmalloc(sizeof(openfilestruct));
newnode->filename = NULL;
return newnode;
}
@ -769,7 +770,7 @@ void free_openfilestruct(openfilestruct *src)
* updated. */
void add_open_file(bool update)
{
if (open_files == NULL && update)
if (update && open_files == NULL)
return;
/* If there are no entries in open_files, make the first one. */

Просмотреть файл

@ -1130,19 +1130,6 @@ void toggle_init(void)
toggle_init_one(TOGGLE_MORESPACE_KEY, N_("Use of more space for editing"),
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 */
/* This function is called just before calling exit(). Practically, the
@ -1162,7 +1149,8 @@ void thanks_for_all_the_fish(void)
free(quotestr);
#ifdef HAVE_REGEX_H
regfree(&quotereg);
free(quoteerr);
if (quoteerr != NULL)
free(quoteerr);
#endif
#endif
#ifndef NANO_SMALL
@ -1219,24 +1207,28 @@ void thanks_for_all_the_fish(void)
free_shortcutage(&browser_list);
free_shortcutage(&gotodir_list);
#endif
#ifndef NANO_SMALL
free_toggles();
#endif
while (toggles != NULL) {
toggle *t = toggles;
toggles = toggles->next;
free(t);
}
#endif
#ifdef ENABLE_MULTIBUFFER
if (open_files != NULL) {
/* We free the memory associated with each open file. */
while (open_files->prev != NULL)
/* Free the memory associated with each open file buffer. */
while (open_files != open_files->prev)
open_files = open_files->prev;
free_openfilestruct(open_files);
}
#else
free_filestruct(fileage);
if (fileage != NULL)
free_filestruct(fileage);
#endif
#ifdef ENABLE_COLOR
free(syntaxstr);
if (syntaxstr != NULL)
free(syntaxstr);
while (syntaxes != NULL) {
syntaxtype *bill = syntaxes;
@ -1264,11 +1256,14 @@ void thanks_for_all_the_fish(void)
#endif /* ENABLE_COLOR */
#ifndef NANO_SMALL
/* Free the history lists. */
free_filestruct(searchage);
free_filestruct(replaceage);
if (searchage != NULL)
free_filestruct(searchage);
if (replaceage != NULL)
free_filestruct(replaceage);
#endif
#ifdef ENABLE_NANORC
free(homedir);
if (homedir != NULL)
free(homedir);
#endif
}
#endif /* DEBUG */

Просмотреть файл

@ -3874,7 +3874,7 @@ bool do_mouse(void)
* TRUE. */
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 do_refresh = FALSE;
/* 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);
current_len = strlen(current->data);
/* Turn off constant cursor position display. */
UNSET(CONSTUPDATE);

Просмотреть файл

@ -329,9 +329,6 @@ size_t length_of_list(const shortcut *s);
#ifndef NANO_SMALL
void toggle_init_one(int val, const char *desc, long flag);
void toggle_init(void);
#ifdef DEBUG
void free_toggles(void);
#endif
#endif
void sc_init_one(shortcut **shortcutage, int key, const char *desc,
#ifndef DISABLE_HELP

Просмотреть файл

@ -2051,12 +2051,13 @@ void do_statusbar_verbatim_input(bool *got_enter)
void do_statusbar_output(char *output, size_t output_len, bool
*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());
int char_buf_len;
assert(answer != NULL);
answer_len = strlen(answer);
*got_enter = FALSE;
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 &&
kbinput != NANO_ENTER_KEY) {
assert(statusbar_x <= answer_len && answer_len == strlen(answer));
assert(statusbar_x <= strlen(answer));
#ifndef DISABLE_TABCOMP
if (kbinput != NANO_TAB_KEY)
@ -2496,7 +2497,7 @@ int nanogetstr(bool allow_tabs, const char *buf, const char *curranswer,
if (allow_tabs) {
answer = input_tab(answer, &statusbar_x, &tabbed,
list);
answer_len = strlen(answer);
statusbar_x = strlen(answer);
}
#endif
break;
@ -2517,8 +2518,7 @@ int nanogetstr(bool allow_tabs, const char *buf, const char *curranswer,
if ((history =
get_history_older(&history_list)) != NULL) {
answer = mallocstrcpy(answer, history);
answer_len = strlen(answer);
statusbar_x = answer_len;
statusbar_x = strlen(answer);
}
/* 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 =
get_history_newer(&history_list)) != NULL) {
answer = mallocstrcpy(answer, history);
answer_len = strlen(answer);
statusbar_x = answer_len;
statusbar_x = strlen(answer);
}
/* 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 &&
answer[0] == '\0' && magichistory != NULL) {
answer = mallocstrcpy(answer, magichistory);
answer_len = strlen(answer);
statusbar_x = answer_len;
statusbar_x = strlen(answer);
}
}
#endif
@ -2880,6 +2878,7 @@ void bottombars(const shortcut *s)
if (s == main_list) {
slen = MAIN_VISIBLE;
assert(slen <= length_of_list(s));
} else {
slen = length_of_list(s);