From 94e563232eec0d4f096fcbc2c00529eeccad1a51 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Thu, 26 Jan 2017 20:05:21 +0100 Subject: [PATCH] general: stop the spell checker from crashing after the changes in search The spell fixer does not provide a beginning line, so the search routine should then not try to refer to any data of this line. Also, since the changes to the search routine there is no need any more to retreat one step before starting to search for a misspelled word. This fixes https://savannah.gnu.org/bugs/?50159. --- src/search.c | 3 ++- src/text.c | 8 +++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/search.c b/src/search.c index ef5fe27c..76ebe4a0 100644 --- a/src/search.c +++ b/src/search.c @@ -283,7 +283,8 @@ int findnextstr(const char *needle, bool whole_word_only, size_t *match_len, /* Ignore the initial match at the starting position: continue * searching from the next character, or invalidate the match. */ - if (skipone || (found == begin->data + begin_x && !came_full_circle)) { + if (skipone || (!whole_word_only && !came_full_circle && + found == begin->data + begin_x)) { skipone = FALSE; if (ISSET(BACKWARDS_SEARCH) && from != line->data) { from = line->data + move_mbleft(line->data, from - line->data); diff --git a/src/text.c b/src/text.c index 7254c9a2..f1049c19 100644 --- a/src/text.c +++ b/src/text.c @@ -2641,11 +2641,10 @@ bool do_int_spell_fix(const char *word) * (current, current_x) (where searching starts) is at the top. */ if (right_side_up) { openfile->current = top; - openfile->current_x = (size_t)(top_x - 1); + openfile->current_x = top_x; openfile->mark_begin = bot; openfile->mark_begin_x = bot_x; - } else - openfile->current_x = (size_t)(openfile->current_x - 1); + } openfile->mark_set = FALSE; } else #endif @@ -2653,7 +2652,7 @@ bool do_int_spell_fix(const char *word) { openfile->edittop = openfile->fileage; openfile->current = openfile->fileage; - openfile->current_x = (size_t)-1; + openfile->current_x = 0; } /* Find the first whole occurrence of word. */ @@ -2685,7 +2684,6 @@ bool do_int_spell_fix(const char *word) /* If a replacement was given, go through all occurrences. */ if (proceed && strcmp(word, answer) != 0) { - openfile->current_x--; #ifndef NANO_TINY /* Replacements should happen only in the marked region. */ openfile->mark_set = old_mark_set;