replace all 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 git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2542 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Этот коммит содержится в:
родитель
16f88134f7
Коммит
e3970f503c
@ -29,6 +29,12 @@ CVS code -
|
||||
do_search(), do_replace(), nanogetstr(), and statusq();
|
||||
removal of remove_node(), insert_node(), and
|
||||
get_history_completion(). (DLR)
|
||||
- Replace all 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)
|
||||
- cut.c:
|
||||
cut_line()
|
||||
- Set placewewant properly after cutting a line, to avoid a
|
||||
@ -84,6 +90,8 @@ 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_regexp()
|
||||
- Rename variable create_flag to create for consistency. (DLR)
|
||||
replace_line()
|
||||
- Make new_line_size and search_match_count size_t's, for
|
||||
consistency. (DLR)
|
||||
|
@ -2222,7 +2222,7 @@ char *input_tab(char *buf, size_t *place, bool *lastwastab, bool *list)
|
||||
*lastwastab = FALSE;
|
||||
buf = charealloc(buf, common_len + buflen - *place + 1);
|
||||
charmove(buf + common_len, buf + *place, buflen - *place + 1);
|
||||
strncpy(buf, mzero, common_len);
|
||||
charcpy(buf, mzero, common_len);
|
||||
*place = common_len;
|
||||
} else if (*lastwastab == FALSE || num_matches < 2)
|
||||
*lastwastab = TRUE;
|
||||
@ -2718,12 +2718,12 @@ char *do_browser(char *path, DIR *dir)
|
||||
* mark it as such. */
|
||||
if (stat(filelist[j], &st) == 0 &&
|
||||
S_ISDIR(st.st_mode)) {
|
||||
strncpy(foo, _("(dir)"), foo_len);
|
||||
charcpy(foo, _("(dir)"), foo_len);
|
||||
foo[foo_len] = '\0';
|
||||
} else
|
||||
strcpy(foo, "--");
|
||||
} else if (S_ISDIR(st.st_mode)) {
|
||||
strncpy(foo, _("(dir)"), foo_len);
|
||||
charcpy(foo, _("(dir)"), foo_len);
|
||||
foo[foo_len] = '\0';
|
||||
} else if (st.st_size < (1 << 10)) /* less than 1 k. */
|
||||
sprintf(foo, "%4u B", (unsigned int)st.st_size);
|
||||
|
@ -1413,7 +1413,7 @@ void do_enter(void)
|
||||
strcpy(&newnode->data[extra], current->data + current_x);
|
||||
#ifndef NANO_SMALL
|
||||
if (ISSET(AUTOINDENT)) {
|
||||
strncpy(newnode->data, current->data, extra);
|
||||
charcpy(newnode->data, current->data, extra);
|
||||
totsize += mbstrlen(newnode->data);
|
||||
}
|
||||
#endif
|
||||
|
@ -513,7 +513,7 @@ void do_research(void);
|
||||
#endif
|
||||
void replace_abort(void);
|
||||
#ifdef HAVE_REGEX_H
|
||||
int replace_regexp(char *string, bool create_flag);
|
||||
int replace_regexp(char *string, bool create);
|
||||
#endif
|
||||
char *replace_line(const char *needle);
|
||||
ssize_t do_replace_loop(const char *needle, const filestruct
|
||||
|
20
src/search.c
20
src/search.c
@ -578,10 +578,10 @@ void replace_abort(void)
|
||||
}
|
||||
|
||||
#ifdef HAVE_REGEX_H
|
||||
int replace_regexp(char *string, bool create_flag)
|
||||
int replace_regexp(char *string, bool create)
|
||||
{
|
||||
/* Split personality here - if create_flag is FALSE, just calculate
|
||||
* the size of the replacement line (necessary because of
|
||||
/* We have a split personality here. If create is FALSE, just
|
||||
* calculate the size of the replacement line (necessary because of
|
||||
* subexpressions \1 to \9 in the replaced text). */
|
||||
|
||||
const char *c = last_replace;
|
||||
@ -595,7 +595,7 @@ int replace_regexp(char *string, bool create_flag)
|
||||
|
||||
if (*c != '\\' || num < 1 || num > 9 ||
|
||||
num > search_regexp.re_nsub) {
|
||||
if (create_flag)
|
||||
if (create)
|
||||
*string++ = *c;
|
||||
c++;
|
||||
new_size++;
|
||||
@ -608,17 +608,17 @@ int replace_regexp(char *string, bool create_flag)
|
||||
/* But add the length of the subexpression to new_size. */
|
||||
new_size += i;
|
||||
|
||||
/* And if create_flag is TRUE, append the result of the
|
||||
/* And if create is TRUE, append the result of the
|
||||
* subexpression match to the new line. */
|
||||
if (create_flag) {
|
||||
strncpy(string, current->data + current_x +
|
||||
if (create) {
|
||||
charcpy(string, current->data + current_x +
|
||||
regmatches[num].rm_so, i);
|
||||
string += i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (create_flag)
|
||||
if (create)
|
||||
*string = '\0';
|
||||
|
||||
return new_size;
|
||||
@ -634,7 +634,7 @@ char *replace_line(const char *needle)
|
||||
#ifdef HAVE_REGEX_H
|
||||
if (ISSET(USE_REGEXP)) {
|
||||
search_match_count = regmatches[0].rm_eo - regmatches[0].rm_so;
|
||||
new_line_size = replace_regexp(NULL, 0);
|
||||
new_line_size = replace_regexp(NULL, FALSE);
|
||||
} else {
|
||||
#endif
|
||||
search_match_count = strlen(needle);
|
||||
@ -648,7 +648,7 @@ char *replace_line(const char *needle)
|
||||
copy = charalloc(new_line_size);
|
||||
|
||||
/* The head of the original line. */
|
||||
strncpy(copy, current->data, current_x);
|
||||
charcpy(copy, current->data, current_x);
|
||||
|
||||
/* The replacement text. */
|
||||
#ifdef HAVE_REGEX_H
|
||||
|
@ -350,7 +350,7 @@ char *mallocstrncpy(char *dest, const char *src, size_t n)
|
||||
free(dest);
|
||||
|
||||
dest = charalloc(n);
|
||||
strncpy(dest, src, n);
|
||||
charcpy(dest, src, n);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user