tweaks: rename a variable, reshuffle declarations, and drop an assert

master
Benno Schulenberg 2019-05-08 15:31:15 +02:00
parent 71d0847b19
commit 247dd8f052
1 changed files with 5 additions and 8 deletions

View File

@ -457,21 +457,20 @@ int replace_regexp(char *string, bool create)
/* Return a copy of the current line with one needle replaced. */
char *replace_line(const char *needle)
{
char *copy;
size_t new_size = strlen(openfile->current->data) + 1;
size_t match_len;
size_t new_line_size = strlen(openfile->current->data) + 1;
char *copy;
/* First adjust the size of the new line for the change. */
if (ISSET(USE_REGEXP)) {
match_len = regmatches[0].rm_eo - regmatches[0].rm_so;
new_line_size += replace_regexp(NULL, FALSE) - match_len;
new_size += replace_regexp(NULL, FALSE) - match_len;
} else {
match_len = strlen(needle);
new_line_size += strlen(answer) - match_len;
new_size += strlen(answer) - match_len;
}
/* Create the buffer. */
copy = charalloc(new_line_size);
copy = charalloc(new_size);
/* Copy the head of the original line. */
strncpy(copy, openfile->current->data, openfile->current_x);
@ -482,8 +481,6 @@ char *replace_line(const char *needle)
else
strcpy(copy + openfile->current_x, answer);
assert(openfile->current_x + match_len <= strlen(openfile->current->data));
/* Copy the tail of the original line. */
strcat(copy, openfile->current->data + openfile->current_x + match_len);