Commit 16799bac authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

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
No related merge requests found
Showing with 26 additions and 22 deletions
+26 -22
...@@ -29,12 +29,11 @@ CVS code - ...@@ -29,12 +29,11 @@ CVS code -
get_history_completion(), do_search(), do_replace(), get_history_completion(), do_search(), do_replace(),
nanogetstr(), and statusq(); removal of remove_node() and nanogetstr(), and statusq(); removal of remove_node() and
insert_node(). (DLR) 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 only difference between them is that the former pads strings
with nulls when they're longer than the number of characters with nulls when they're longer than the number of characters
specified, which doesn't appear to be used anywhere. Changes specified, which isn't always used. Changes to input_tab(),
to input_tab(), do_browser(), do_enter(), replace_regexp(), do_enter(), replace_regexp(), and replace_line(). (DLR)
replace_line(), and mallocstrncpy(). (DLR)
- When using a backup directory, make sure all the filenames - When using a backup directory, make sure all the filenames
written are unique by using get_next_filename() when written are unique by using get_next_filename() when
necessary. Changes to get_next_filename(), write_file(), necessary. Changes to get_next_filename(), write_file(),
...@@ -162,6 +161,7 @@ CVS code - ...@@ -162,6 +161,7 @@ CVS code -
- Add multibyte/wide character support, so that we don't end up - Add multibyte/wide character support, so that we don't end up
with a string that contains only part of a multibyte with a string that contains only part of a multibyte
character during tab completion. (DLR) character during tab completion. (DLR)
- Rename variable buflen to buf_len, for consistency. (DLR)
do_browser() do_browser()
- Don't treat NANO_CANCEL_KEY as NANO_EXIT_KEY anymore, for - Don't treat NANO_CANCEL_KEY as NANO_EXIT_KEY anymore, for
consistency. (DLR) consistency. (DLR)
...@@ -172,6 +172,7 @@ CVS code - ...@@ -172,6 +172,7 @@ CVS code -
consistency. (DLR) consistency. (DLR)
- Make mouse clicks in the browser window work properly when the - Make mouse clicks in the browser window work properly when the
MORE_SPACE flag is set. (DLR) MORE_SPACE flag is set. (DLR)
- Make foo_len a size_t instead of an int. (DLR)
save_history() save_history()
- Properly save history when we're in view mode. (DLR) - Properly save history when we're in view mode. (DLR)
- global.c: - global.c:
...@@ -270,7 +271,10 @@ CVS code - ...@@ -270,7 +271,10 @@ CVS code -
- Start the search for a line from fileage instead of current - Start the search for a line from fileage instead of current
(again). (DLR) (again). (DLR)
replace_regexp() 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() replace_line()
- Make new_line_size and search_match_count size_t's, for - Make new_line_size and search_match_count size_t's, for
consistency. (DLR) consistency. (DLR)
......
...@@ -2271,12 +2271,12 @@ char *input_tab(char *buf, size_t *place, bool *lastwastab, bool *list) ...@@ -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 * twice in succession with no statusbar changes to see a match
* list. */ * list. */
if (common_len != *place) { if (common_len != *place) {
size_t buflen = strlen(buf); size_t buf_len = strlen(buf);
*lastwastab = FALSE; *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, charmove(buf + common_len, buf + *place,
buflen - *place + 1); buf_len - *place + 1);
charcpy(buf, mzero, common_len); charcpy(buf, mzero, common_len);
*place = common_len; *place = common_len;
} else if (*lastwastab == FALSE || num_matches < 2) } else if (*lastwastab == FALSE || num_matches < 2)
...@@ -2736,7 +2736,7 @@ char *do_browser(char *path, DIR *dir) ...@@ -2736,7 +2736,7 @@ char *do_browser(char *path, DIR *dir)
wmove(edit, 0, 0); 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); char *foo = charalloc(foo_len + 1);
for (; j < numents && editline <= editwinrows - 1; j++) { for (; j < numents && editline <= editwinrows - 1; j++) {
...@@ -2764,15 +2764,13 @@ char *do_browser(char *path, DIR *dir) ...@@ -2764,15 +2764,13 @@ char *do_browser(char *path, DIR *dir)
/* Aha! It's a symlink! Now, is it a dir? If so, /* Aha! It's a symlink! Now, is it a dir? If so,
* mark it as such. */ * mark it as such. */
if (stat(filelist[j], &st) == 0 && if (stat(filelist[j], &st) == 0 &&
S_ISDIR(st.st_mode)) { S_ISDIR(st.st_mode))
charcpy(foo, _("(dir)"), foo_len); strncpy(foo, _("(dir)"), foo_len);
foo[foo_len] = '\0'; else
} else
strcpy(foo, "--"); strcpy(foo, "--");
} else if (S_ISDIR(st.st_mode)) { } else if (S_ISDIR(st.st_mode))
charcpy(foo, _("(dir)"), foo_len); strncpy(foo, _("(dir)"), foo_len);
foo[foo_len] = '\0'; else if (st.st_size < (1 << 10)) /* less than 1 k. */
} else if (st.st_size < (1 << 10)) /* less than 1 k. */
sprintf(foo, "%4u B", (unsigned int)st.st_size); sprintf(foo, "%4u B", (unsigned int)st.st_size);
else if (st.st_size < (1 << 20)) /* less than 1 meg. */ else if (st.st_size < (1 << 20)) /* less than 1 meg. */
sprintf(foo, "%4u KB", sprintf(foo, "%4u KB",
......
...@@ -585,8 +585,10 @@ int replace_regexp(char *string, bool create) ...@@ -585,8 +585,10 @@ int replace_regexp(char *string, bool create)
* subexpressions \1 to \9 in the replaced text). */ * subexpressions \1 to \9 in the replaced text). */
const char *c = last_replace; const char *c = last_replace;
int search_match_count = regmatches[0].rm_eo - regmatches[0].rm_so; size_t search_match_count =
int new_size = strlen(current->data) + 1 - 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 /* Iterate through the replacement text to handle subexpression
* replacement using \1, \2, \3, etc. */ * replacement using \1, \2, \3, etc. */
...@@ -600,7 +602,7 @@ int replace_regexp(char *string, bool create) ...@@ -600,7 +602,7 @@ int replace_regexp(char *string, bool create)
c++; c++;
new_size++; new_size++;
} else { } 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. */ /* Skip over the replacement expression. */
c += 2; c += 2;
...@@ -621,7 +623,7 @@ int replace_regexp(char *string, bool create) ...@@ -621,7 +623,7 @@ int replace_regexp(char *string, bool create)
if (create) if (create)
*string = '\0'; *string = '\0';
return new_size; return new_line_size;
} }
#endif #endif
......
...@@ -350,7 +350,7 @@ char *mallocstrncpy(char *dest, const char *src, size_t n) ...@@ -350,7 +350,7 @@ char *mallocstrncpy(char *dest, const char *src, size_t n)
free(dest); free(dest);
dest = charalloc(n); dest = charalloc(n);
charcpy(dest, src, n); strncpy(dest, src, n);
return dest; return dest;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment