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
master
David Lawrence Ramsey 2005-06-21 22:32:50 +00:00
parent d4ea5b69c5
commit 16799baccd
4 changed files with 26 additions and 22 deletions

View File

@ -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)

View File

@ -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",

View File

@ -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

View File

@ -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;
}