From fe9cf6f399bdd8366c1c456a018ea1aa6125d5b4 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 8 May 2016 10:41:53 +0200 Subject: [PATCH] tweaks: make advancing and retreating more symmetrical --- src/utils.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/utils.c b/src/utils.c index d3ae76cc..9a2f02da 100644 --- a/src/utils.c +++ b/src/utils.c @@ -611,20 +611,21 @@ size_t get_totsize(const filestruct *begin, const filestruct *end) return totsize; } -/* Get back a pointer given a line number in the current openfilestruct. */ +/* Given a line number, return a pointer to the corresponding struct. */ filestruct *fsfromline(ssize_t lineno) { filestruct *f = openfile->current; if (lineno <= openfile->current->lineno) - for (; f->lineno != lineno && f != openfile->fileage; f = f->prev) - ; + while (f->lineno != lineno && f->prev != NULL) + f = f->prev; else - for (; f->lineno != lineno && f->next != NULL; f = f->next) - ; + while (f->lineno != lineno && f->next != NULL) + f = f->next; if (f->lineno != lineno) - f = NULL; + return NULL; + return f; }