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)
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,
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)
openfilestruct *newnode =
(openfilestruct *)nmalloc(sizeof(openfilestruct));
newnode->filename = NULL;
+
return newnode;
}
* 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. */
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
free(quotestr);
#ifdef HAVE_REGEX_H
regfree("ereg);
- free(quoteerr);
+ if (quoteerr != NULL)
+ free(quoteerr);
#endif
#endif
#ifndef NANO_SMALL
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;
#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 */
* 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
assert(current != NULL && current->data != NULL);
+ current_len = strlen(current->data);
+
/* Turn off constant cursor position display. */
UNSET(CONSTUPDATE);
#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
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) {
&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)
if (allow_tabs) {
answer = input_tab(answer, &statusbar_x, &tabbed,
list);
- answer_len = strlen(answer);
+ statusbar_x = strlen(answer);
}
#endif
break;
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
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
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
if (s == main_list) {
slen = MAIN_VISIBLE;
+
assert(slen <= length_of_list(s));
} else {
slen = length_of_list(s);