commit 247dd8f052b30092afacd984564552c4d7bc718a
parent 71d0847b19a8c2a7f12d6c970bc84897e73235aa
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Wed, 8 May 2019 15:31:15 +0200
tweaks: rename a variable, reshuffle declarations, and drop an assert
Diffstat:
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/src/search.c b/src/search.c
@@ -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);