From 06b449b22c85cce628875cf80fbaa3ae21eb8259 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Sun, 8 May 2016 10:51:40 +0200
Subject: [PATCH] utils: provide a failure message for all uses of 'fsfromline'

---
 src/text.c  | 19 ++++++++-----------
 src/utils.c |  5 ++++-
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/text.c b/src/text.c
index 2e9210e8..95290108 100644
--- a/src/text.c
+++ b/src/text.c
@@ -478,7 +478,7 @@ void redo_cut(undo *u)
 void do_undo(void)
 {
     undo *u = openfile->current_undo;
-    filestruct *t = NULL;
+    filestruct *f, *t = NULL;
     char *data, *undidmsg = NULL;
 
     if (!u) {
@@ -486,12 +486,10 @@ void do_undo(void)
 	return;
     }
 
-    filestruct *f = fsfromline(u->mark_begin_lineno);
-    if (!f) {
-	statusbar(_("Internal error: can't match line %d.  "
-			"Please save your work."), u->mark_begin_lineno);
+    f = fsfromline(u->mark_begin_lineno);
+    if (!f)
 	return;
-    }
+
 #ifdef DEBUG
     fprintf(stderr, "  >> Undoing a type %d...\n", u->type);
     fprintf(stderr, "  >> Data we're about to undo = \"%s\"\n", f->data);
@@ -621,6 +619,7 @@ void do_undo(void)
 /* Redo the last thing(s) we undid. */
 void do_redo(void)
 {
+    filestruct *f;
     char *data, *redidmsg = NULL;
     undo *u = openfile->undotop;
 
@@ -638,12 +637,10 @@ void do_redo(void)
 	return;
     }
 
-    filestruct *f = fsfromline(u->type == INSERT ? 1 : u->mark_begin_lineno);
-    if (!f) {
-	statusbar(_("Internal error: can't match line %d.  "
-			"Please save your work."), u->mark_begin_lineno);
+    f = fsfromline(u->type == INSERT ? 1 : u->mark_begin_lineno);
+    if (!f)
 	return;
-    }
+
 #ifdef DEBUG
     fprintf(stderr, "  >> Redo running for type %d\n", u->type);
     fprintf(stderr, "  >> Data we're about to redo = \"%s\"\n", f->data);
diff --git a/src/utils.c b/src/utils.c
index 9a2f02da..592fca49 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -623,8 +623,11 @@ filestruct *fsfromline(ssize_t lineno)
 	while (f->lineno != lineno && f->next != NULL)
 	    f = f->next;
 
-    if (f->lineno != lineno)
+    if (f->lineno != lineno) {
+	statusbar(_("Internal error: can't match line %d.  "
+			"Please save your work."), lineno);
 	return NULL;
+    }
 
     return f;
 }
-- 
GitLab