From 654d694e39c367cefc8e6b5f480179a5acb8fb7e Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Thu, 9 Apr 2020 12:52:36 +0200 Subject: [PATCH] tweaks: simplify the counting of characters in a section The line after the given section is always NULL (or when it is not, it is intended to be NULL), so always subtract 1 at the end. --- src/text.c | 3 +-- src/utils.c | 8 ++------ src/winio.c | 4 ---- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/text.c b/src/text.c index a0f4dc07..7b7f51e4 100644 --- a/src/text.c +++ b/src/text.c @@ -2920,10 +2920,9 @@ void do_wordlinechar_count(void) get_region(&topline, &top_x, &botline, &bot_x); if (topline != botline) - chars = number_of_characters_in(topline->next, botline); + chars = number_of_characters_in(topline->next, botline) + 1; chars += mbstrlen(topline->data + top_x) - mbstrlen(botline->data + bot_x); - chars += (botline->next == NULL) ? 1 : 0; } else { topline = openfile->filetop; top_x = 0; diff --git a/src/utils.c b/src/utils.c index dd3bcc50..a4b5b277 100644 --- a/src/utils.c +++ b/src/utils.c @@ -521,10 +521,6 @@ size_t number_of_characters_in(const linestruct *begin, const linestruct *end) for (line = begin; line != end->next; line = line->next) count += mbstrlen(line->data) + 1; - /* The last line of a file doesn't have a newline -- otherwise it - * wouldn't be the last line -- so subtract 1 when at EOF. */ - if (line == NULL) - count--; - - return count; + /* Do not count the final newline. */ + return (count - 1); } diff --git a/src/winio.c b/src/winio.c index a1f38d1d..e7dbba39 100644 --- a/src/winio.c +++ b/src/winio.c @@ -3342,10 +3342,6 @@ void do_cursorpos(bool force) openfile->current->data[openfile->current_x] = saved_byte; - /* When not at EOF, subtract 1 for an overcounted newline. */ - if (openfile->current != openfile->filebot) - sum--; - /* Display the current cursor position on the status bar. */ linepct = 100 * openfile->current->lineno / openfile->filebot->lineno; colpct = 100 * cur_xpt / cur_lenpt;