[PATCH 3/3] files: avoid mistakenly setting the column number to a given line number

Benno Schulenberg <[email protected]>
Newsgroups gmane.editors.nano.devel
Message-ID <[email protected]>
When the file 'foo:24' exists (but not 'foo') and the user wants to
use the colon notation to place the cursor on a certain line, then
nano would first interpret the given line number as a column number,
before noticing that 'foo' does not exist and then skipping the first
colon.  So, when such a misinterpretation occurs, the column number
needs to be reset to zero.
---
 src/nano.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/nano.c b/src/nano.c
index 0821dfaf..b1fe2bec 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -2509,8 +2509,10 @@ int main(int argc, char **argv)
 						memmove(colon - 1, colon, strlen(colon) + 1);
 					else if (parse_line_column(colon + 1, &givenline, &givencol)) {
 						*colon = '\0';
-						if (stat(filename, &fileinfo) < 0)
+						if (stat(filename, &fileinfo) < 0) {
 							*colon++ = ':';
+							givencol = 0;
+						}
 					} else
 						++colon;
 				}
-- 
2.42.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.