From faf5227bc5ee587c3f03a97443a5e2e3e722db74 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Wed, 18 May 2016 13:18:07 +0200
Subject: [PATCH] files: remove a superfluous condition, and do not ignore a
 "No"

Having just opened a fresh buffer, 'openfile->next' will never be NULL,
because the list is circular.

Second, when compiled with --disable-nultibuffer, and deciding not to
override an existing lock, the 'return FALSE' should *not* be skipped,
because otherwise the named file will be opened after all.

This fixes an unreported bug.
---
 src/files.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/files.c b/src/files.c
index 90d9ed73..fbf81cfb 100644
--- a/src/files.c
+++ b/src/files.c
@@ -456,14 +456,13 @@ bool open_buffer(const char *filename, bool undoable)
 	if (has_valid_path(realname)) {
 #ifndef NANO_TINY
 	    if (ISSET(LOCKING) && filename[0] != '\0') {
+		/* When not overriding an existing lock, discard the buffer. */
 		if (do_lockfile(realname) < 0) {
 #ifndef DISABLE_MULTIBUFFER
-		    if (openfile->next) {
-			close_buffer();
-			free(realname);
-			return FALSE;
-		    }
+		    close_buffer();
 #endif
+		    free(realname);
+		    return FALSE;
 		}
 	    }
 #endif /* !NANO_TINY */
-- 
GitLab