diff --git a/src/nano.c b/src/nano.c
index aed58d886619c85d900bcc37bb6708fe78d6cec9..260784ce4ec4fad2bffe625ecf95153bb394a291 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -2605,9 +2605,9 @@ int main(int argc, char **argv)
 		/* If the filename is a dash, read from standard input; otherwise,
 		 * open the file; skip positioning the cursor if either failed. */
 		if (strcmp(argv[optind], "-") == 0) {
+			optind++;
 			if (!scoop_stdin())
 				continue;
-			optind++;
 		} else if (!open_buffer(argv[optind++], FALSE))
 			continue;