diff --git a/ChangeLog b/ChangeLog
index 89ff5007f43771606d6e5348ac9b6c45234981f9..bafff506aa7fb25ad6239465ecc5128d3c678927 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-12-30  Benno Schulenberg  <bensberg@justemail.net>
+	* src/nano.c (main), src/files.c (open_buffer): Don't try to position
+	the cursor when opening a buffer failed (because the user specified a
+	directory, for example).  This fixes Savannah bug #46778.
+
 2015-12-29  Benno Schulenberg  <bensberg@justemail.net>
 	* doc/syntax/{c,objc,asm}.nanorc: Disable the regex for multiline
 	strings as it colours some things wrong and is a glutton on time.
diff --git a/src/files.c b/src/files.c
index 590348446ebfe1a5e786c0877762b807485a11de..5e421372c92041fa1a0df4e49e6a7b4671996e78 100644
--- a/src/files.c
+++ b/src/files.c
@@ -323,7 +323,7 @@ int do_lockfile(const char *filename)
 
 /* If it's not "", filename is a file to open.  We make a new buffer, if
  * necessary, and then open and read the file, if applicable. */
-void open_buffer(const char *filename, bool undoable)
+bool open_buffer(const char *filename, bool undoable)
 {
     bool quiet = FALSE;
     bool new_buffer = (openfile == NULL
@@ -343,7 +343,7 @@ void open_buffer(const char *filename, bool undoable)
     if (check_operating_dir(filename, FALSE)) {
 	statusbar(_("Can't insert file from outside of %s"),
 		operating_dir);
-	return;
+	return FALSE;
     }
 #endif
 
@@ -358,7 +358,7 @@ void open_buffer(const char *filename, bool undoable)
 	    else
 		statusbar(_("\"%s\" is not a normal file"), filename);
 	    beep();
-	    return;
+	    return FALSE;
 	}
     }
 
@@ -374,7 +374,7 @@ void open_buffer(const char *filename, bool undoable)
 #ifndef DISABLE_MULTIBUFFER
 		if (openfile->next) {
 		    close_buffer(TRUE);
-		    return;
+		    return FALSE;
 		}
 #endif
 	    } else if (lockstatus == 0) {
@@ -421,6 +421,7 @@ void open_buffer(const char *filename, bool undoable)
     if (new_buffer)
 	color_update();
 #endif
+    return TRUE;
 }
 
 #ifndef DISABLE_SPELLER
diff --git a/src/nano.c b/src/nano.c
index dc9981064ca4887341f6c99a98cd6d8c272b4805..9066bf0efb729f420e43f07c0be823425dabbb46 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -2622,7 +2622,9 @@ int main(int argc, char **argv)
 	    if (i < argc - 1 && argv[i][0] == '+')
 		parse_line_column(&argv[i][1], &iline, &icol);
 	    else {
-		open_buffer(argv[i], FALSE);
+		/* If opening fails, don't try to position the cursor. */
+		if (!open_buffer(argv[i], FALSE))
+		    continue;
 
 		/* If a position was given on the command line, go there. */
 		if (iline > 0 || icol > 0) {
diff --git a/src/proto.h b/src/proto.h
index 0d2683c2390780080ec3bd898b74ee8274048ae3..566790d4d586b9a8084fe33bcae2472a819179d5 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -283,7 +283,7 @@ void do_uncut_text(void);
 /* All functions in files.c. */
 void make_new_buffer(void);
 void initialize_buffer_text(void);
-void open_buffer(const char *filename, bool undoable);
+bool open_buffer(const char *filename, bool undoable);
 #ifndef DISABLE_SPELLER
 void replace_buffer(const char *filename);
 #endif