From 16f88134f7d5f0b697aabc5a2f48be37e44bd2c4 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Thu, 26 May 2005 03:32:41 +0000 Subject: [PATCH] more miscellaneous minor fixes git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2541 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 6 ++++++ src/files.c | 13 +++++++++---- src/search.c | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index b1346ef0..c4b19680 100644 --- a/ChangeLog +++ b/ChangeLog @@ -52,6 +52,9 @@ CVS code - do_browser() - Don't treat NANO_CANCEL_KEY as NANO_EXIT_KEY anymore, for consistency. (DLR) + - When displaying "(dir)" in the available screen space, make + sure that the string it's stored in is always null-terminated. + (DLR) save_history() - Properly save history when in view mode. (DLR) - global.c: @@ -81,6 +84,9 @@ CVS code - since the first line in the file is 1. (DLR) - Start the search for a line from fileage instead of current (again). (DLR) + replace_line() + - Make new_line_size and search_match_count size_t's, for + consistency. (DLR) - utils.c: num_of_digits() - Use a size_t instead of an int, and rename to digits(). (DLR) diff --git a/src/files.c b/src/files.c index c7a1502e..b6611b9f 100644 --- a/src/files.c +++ b/src/files.c @@ -2204,6 +2204,7 @@ char *input_tab(char *buf, size_t *place, bool *lastwastab, bool *list) if (num_matches == 1 && is_dir(mzero)) { mzero[common_len] = '/'; common_len++; + assert(common_len > *place); } @@ -2266,8 +2267,9 @@ char *input_tab(char *buf, size_t *place, bool *lastwastab, bool *list) wmove(edit, editline, (longest_name + 2) * (match % columns)); - if (match % columns == 0 && editline == editwinrows - 1 - && num_matches - match > columns) { + if (match % columns == 0 && + editline == editwinrows - 1 && + num_matches - match > columns) { waddstr(edit, _("(more)")); break; } @@ -2321,6 +2323,7 @@ void free_charptrarray(char **array, size_t len) { for (; len > 0; len--) free(array[len - 1]); + free(array); } @@ -2332,6 +2335,7 @@ void striponedir(char *path) assert(path != NULL); tmp = strrchr(path, '/'); + if (tmp != NULL) *tmp = '\0'; } @@ -2718,9 +2722,10 @@ char *do_browser(char *path, DIR *dir) foo[foo_len] = '\0'; } else strcpy(foo, "--"); - } else if (S_ISDIR(st.st_mode)) + } else if (S_ISDIR(st.st_mode)) { strncpy(foo, _("(dir)"), foo_len); - else if (st.st_size < (1 << 10)) /* less than 1 k. */ + foo[foo_len] = '\0'; + } else if (st.st_size < (1 << 10)) /* less than 1 k. */ sprintf(foo, "%4u B", (unsigned int)st.st_size); else if (st.st_size < (1 << 20)) /* less than 1 meg. */ sprintf(foo, "%4u KB", diff --git a/src/search.c b/src/search.c index 89e816ec..6c670fa4 100644 --- a/src/search.c +++ b/src/search.c @@ -628,8 +628,7 @@ int replace_regexp(char *string, bool create_flag) char *replace_line(const char *needle) { char *copy; - int new_line_size; - int search_match_count; + size_t new_line_size, search_match_count; /* Calculate the size of the new line. */ #ifdef HAVE_REGEX_H @@ -661,6 +660,7 @@ char *replace_line(const char *needle) /* The tail of the original line. */ assert(current_x + search_match_count <= strlen(current->data)); + strcat(copy, current->data + current_x + search_match_count); return copy; -- 2.39.5