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(),
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;
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
#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;
}
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') {
* 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);
charmove(¤t->data[current_x + char_buf_len],
¤t->data[current_x],
current_len - current_x + char_buf_len);
- charcpy(¤t->data[current_x], char_buf, char_buf_len);
+ strncpy(¤t->data[current_x], char_buf, char_buf_len);
current_len += char_buf_len;
totsize++;
set_modified();
#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. */
/* 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;
}
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
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();