From 16799baccd5afd4c35d042e8cb4061250b01f48b Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Tue, 21 Jun 2005 22:32:50 +0000 Subject: [PATCH] change some instances of charcpy() back to strncpy(), as the latter's numm-termination is needed in some places git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2755 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 14 +++++++++----- src/files.c | 22 ++++++++++------------ src/search.c | 10 ++++++---- src/utils.c | 2 +- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index bb762129..484fbd76 100644 --- a/ChangeLog +++ b/ChangeLog @@ -29,12 +29,11 @@ CVS code - get_history_completion(), do_search(), do_replace(), nanogetstr(), and statusq(); removal of remove_node() and insert_node(). (DLR) - - Replace all instances of strncpy() with charcpy(), since the + - Replace more instances of strncpy() with charcpy(), since the only difference between them is that the former pads strings with nulls when they're longer than the number of characters - specified, which doesn't appear to be used anywhere. Changes - to input_tab(), do_browser(), do_enter(), replace_regexp(), - replace_line(), and mallocstrncpy(). (DLR) + specified, which isn't always used. Changes to input_tab(), + do_enter(), replace_regexp(), and replace_line(). (DLR) - When using a backup directory, make sure all the filenames written are unique by using get_next_filename() when necessary. Changes to get_next_filename(), write_file(), @@ -162,6 +161,7 @@ CVS code - - Add multibyte/wide character support, so that we don't end up with a string that contains only part of a multibyte character during tab completion. (DLR) + - Rename variable buflen to buf_len, for consistency. (DLR) do_browser() - Don't treat NANO_CANCEL_KEY as NANO_EXIT_KEY anymore, for consistency. (DLR) @@ -172,6 +172,7 @@ CVS code - consistency. (DLR) - Make mouse clicks in the browser window work properly when the MORE_SPACE flag is set. (DLR) + - Make foo_len a size_t instead of an int. (DLR) save_history() - Properly save history when we're in view mode. (DLR) - global.c: @@ -270,7 +271,10 @@ CVS code - - Start the search for a line from fileage instead of current (again). (DLR) replace_regexp() - - Rename variable create_flag to create for consistency. (DLR) + - Rename variables create_flag and new_size to create and + new_line_size, for consistency. (DLR) + - Make new_line_size, search_match_count, and i size_t's, for + consistency. (DLR) replace_line() - Make new_line_size and search_match_count size_t's, for consistency. (DLR) diff --git a/src/files.c b/src/files.c index 04af248f..ecba871a 100644 --- a/src/files.c +++ b/src/files.c @@ -2271,12 +2271,12 @@ char *input_tab(char *buf, size_t *place, bool *lastwastab, bool *list) * twice in succession with no statusbar changes to see a match * list. */ if (common_len != *place) { - size_t buflen = strlen(buf); + size_t buf_len = strlen(buf); *lastwastab = FALSE; - buf = charealloc(buf, common_len + buflen - *place + 1); + buf = charealloc(buf, common_len + buf_len - *place + 1); charmove(buf + common_len, buf + *place, - buflen - *place + 1); + buf_len - *place + 1); charcpy(buf, mzero, common_len); *place = common_len; } else if (*lastwastab == FALSE || num_matches < 2) @@ -2736,7 +2736,7 @@ char *do_browser(char *path, DIR *dir) wmove(edit, 0, 0); { - int foo_len = mb_cur_max() * 7; + size_t foo_len = mb_cur_max() * 7; char *foo = charalloc(foo_len + 1); for (; j < numents && editline <= editwinrows - 1; j++) { @@ -2764,15 +2764,13 @@ char *do_browser(char *path, DIR *dir) /* Aha! It's a symlink! Now, is it a dir? If so, * mark it as such. */ if (stat(filelist[j], &st) == 0 && - S_ISDIR(st.st_mode)) { - charcpy(foo, _("(dir)"), foo_len); - foo[foo_len] = '\0'; - } else + S_ISDIR(st.st_mode)) + strncpy(foo, _("(dir)"), foo_len); + else strcpy(foo, "--"); - } else if (S_ISDIR(st.st_mode)) { - charcpy(foo, _("(dir)"), foo_len); - foo[foo_len] = '\0'; - } else if (st.st_size < (1 << 10)) /* less than 1 k. */ + } else if (S_ISDIR(st.st_mode)) + strncpy(foo, _("(dir)"), foo_len); + 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 25cc0605..54cd7c50 100644 --- a/src/search.c +++ b/src/search.c @@ -585,8 +585,10 @@ int replace_regexp(char *string, bool create) * subexpressions \1 to \9 in the replaced text). */ const char *c = last_replace; - int search_match_count = regmatches[0].rm_eo - regmatches[0].rm_so; - int new_size = strlen(current->data) + 1 - search_match_count; + size_t search_match_count = + regmatches[0].rm_eo - regmatches[0].rm_so; + size_t new_line_size = + strlen(current->data) + 1 - search_match_count; /* Iterate through the replacement text to handle subexpression * replacement using \1, \2, \3, etc. */ @@ -600,7 +602,7 @@ int replace_regexp(char *string, bool create) c++; new_size++; } else { - int i = regmatches[num].rm_eo - regmatches[num].rm_so; + size_t i = regmatches[num].rm_eo - regmatches[num].rm_so; /* Skip over the replacement expression. */ c += 2; @@ -621,7 +623,7 @@ int replace_regexp(char *string, bool create) if (create) *string = '\0'; - return new_size; + return new_line_size; } #endif diff --git a/src/utils.c b/src/utils.c index 1798c93b..837ff4ea 100644 --- a/src/utils.c +++ b/src/utils.c @@ -350,7 +350,7 @@ char *mallocstrncpy(char *dest, const char *src, size_t n) free(dest); dest = charalloc(n); - charcpy(dest, src, n); + strncpy(dest, src, n); return dest; }