1
1

remove all instances of charcpy() and replace them with strncpy(), for

ease of maintenance


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2758 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Этот коммит содержится в:
David Lawrence Ramsey 2005-06-22 00:24:11 +00:00
родитель bebfc6da0f
Коммит 7a3f49c019
6 изменённых файлов: 14 добавлений и 15 удалений

Просмотреть файл

@ -29,11 +29,11 @@ CVS code -
get_history_completion(), do_search(), do_replace(),
nanogetstr(), and statusq(); removal of remove_node() and
insert_node(). (DLR)
- 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 isn't always used. Changes to input_tab(),
do_enter(), replace_regexp(), and replace_line(). (DLR)
- Remove all instances of charcpy() and replace them with
strncpy(), since there's no way to be sure that a charcpy()ed
string will always be properly null-terminated, and strcpy()'s
null termination is the only difference between it and
charcpy(). (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(),

Просмотреть файл

@ -2277,7 +2277,7 @@ char *input_tab(char *buf, size_t *place, bool *lastwastab, bool *list)
buf = charealloc(buf, common_len + buf_len - *place + 1);
charmove(buf + common_len, buf + *place,
buf_len - *place + 1);
charcpy(buf, mzero, common_len);
strncpy(buf, mzero, common_len);
*place = common_len;
} else if (*lastwastab == FALSE || num_matches < 2)
*lastwastab = TRUE;

Просмотреть файл

@ -1439,7 +1439,7 @@ void do_enter(void)
strcpy(&newnode->data[extra], current->data + current_x);
#ifndef NANO_SMALL
if (ISSET(AUTOINDENT)) {
charcpy(newnode->data, current->data, extra);
strncpy(newnode->data, current->data, extra);
totsize += mbstrlen(newnode->data);
}
#endif
@ -1875,7 +1875,7 @@ bool do_wrap(filestruct *line)
#ifndef NANO_SMALL
if (ISSET(AUTOINDENT)) {
/* Copy the indentation. */
charcpy(new_line, indent_string, indent_len);
strncpy(new_line, indent_string, indent_len);
new_line[indent_len] = '\0';
new_line_len += indent_len;
}
@ -2657,7 +2657,7 @@ void justify_format(filestruct *paragraph, size_t skip)
end = paragraph->data + skip;
new_paragraph_data = charalloc(strlen(paragraph->data) + 1);
charcpy(new_paragraph_data, paragraph->data, skip);
strncpy(new_paragraph_data, paragraph->data, skip);
new_end = new_paragraph_data + skip;
while (*end != '\0') {
@ -3323,7 +3323,7 @@ void do_justify(bool full_justify)
* current line to the next line. */
current->next->data = charalloc(indent_len + 1 + line_len -
break_pos);
charcpy(current->next->data, indent_string, indent_len);
strncpy(current->next->data, indent_string, indent_len);
strcpy(current->next->data + indent_len, current->data +
break_pos);
@ -4048,7 +4048,7 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
charmove(&current->data[current_x + char_buf_len],
&current->data[current_x],
current_len - current_x + char_buf_len);
charcpy(&current->data[current_x], char_buf, char_buf_len);
strncpy(&current->data[current_x], char_buf, char_buf_len);
current_len += char_buf_len;
totsize++;
set_modified();

Просмотреть файл

@ -49,7 +49,6 @@
#define charalloc(howmuch) (char *)nmalloc((howmuch) * sizeof(char))
#define charealloc(ptr, howmuch) (char *)nrealloc(ptr, (howmuch) * sizeof(char))
#define charmove(dest, src, n) memmove(dest, src, (n) * sizeof(char))
#define charcpy(dest, src, n) memcpy(dest, src, (n) * sizeof(char))
#define charset(dest, src, n) memset(dest, src, (n) * sizeof(char))
/* Other macros. */

Просмотреть файл

@ -613,7 +613,7 @@ int replace_regexp(char *string, bool create)
/* And if create is TRUE, append the result of the
* subexpression match to the new line. */
if (create) {
charcpy(string, current->data + current_x +
strncpy(string, current->data + current_x +
regmatches[num].rm_so, i);
string += i;
}
@ -650,7 +650,7 @@ char *replace_line(const char *needle)
copy = charalloc(new_line_size);
/* The head of the original line. */
charcpy(copy, current->data, current_x);
strncpy(copy, current->data, current_x);
/* The replacement text. */
#ifdef HAVE_REGEX_H

Просмотреть файл

@ -2101,7 +2101,7 @@ void do_statusbar_output(char *output, size_t output_len, bool
charmove(&answer[statusbar_x + char_buf_len],
&answer[statusbar_x], answer_len - statusbar_x +
char_buf_len);
charcpy(&answer[statusbar_x], char_buf, char_buf_len);
strncpy(&answer[statusbar_x], char_buf, char_buf_len);
answer_len += char_buf_len;
do_statusbar_right();