From 673f7367c0653c3ab75b0b75145cac9b812507f5 Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Sun, 15 Nov 2015 06:28:19 +0000 Subject: [PATCH] Backport of r5304 and r5307 from trunk. git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_2_4_branch@5408 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 19 ++++++++++++++++++- src/files.c | 18 ++++++++++++++++++ src/winio.c | 11 +++++++---- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2208116a..66c1a807 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,22 @@ +2015-07-18 Benno Schulenberg + * src/winio.c (edit_draw): When looking for multiline-regex matches, + look for a new start only after an end, instead of right after the + last start. This fixes bug #45525 and bug #41313 on Savannah. + +2015-07-17 Benno Schulenberg + * src/files.c (open_buffer): Verify that a named and existing file + is a normal file, to avoid opening an empty buffer when the name of + a directory is specified. This fixes Savannah bug #45383 reported + by Mike Frysinger, and also Savannah bug #27839 (which is an echo + from Debian bug #551717 reported by Paul Wise). + + +2015-07-13 Benno Schulenberg + * src/files.c (replace_buffer): Prevent a segfault when spellchecking + a marked region and nonewlines isn't set. + 2015-07-10 Benno Schulenberg - * src/nano.c (delete_opennode): Plug a small memory leak. + * src/nano.c (delete_opennode): Plug a small memory leak. 2015-06-28 Benno Schulenberg * src/global.c (add_to_sclist), src/help.c (help_init), src/nano.h, diff --git a/src/files.c b/src/files.c index ca8848ff..582ef714 100644 --- a/src/files.c +++ b/src/files.c @@ -339,6 +339,21 @@ void open_buffer(const char *filename, bool undoable) } #endif + /* When the specified filename is not empty, and the thing exists, + * verify that it is a normal file. */ + if (strcmp(filename, "") != 0) { + struct stat fileinfo; + + if (stat(filename, &fileinfo) == 0 && !S_ISREG(fileinfo.st_mode)) { + if (S_ISDIR(fileinfo.st_mode)) + statusbar(_("\"%s\" is a directory"), filename); + else + statusbar(_("\"%s\" is not a normal file"), filename); + beep(); + return; + } + } + /* If we're loading into a new buffer, add a new entry to * openfile. */ if (new_buffer) { @@ -420,6 +435,9 @@ void replace_buffer(const char *filename) /* If opening the file succeeded, read it in. */ if (descriptor > 0) read_file(f, descriptor, filename, FALSE, TRUE); + + /* Put current at a place that is certain to exist. */ + openfile->current = openfile->fileage; } #endif /* !DISABLE_SPELLER */ diff --git a/src/winio.c b/src/winio.c index c152b64c..614d0746 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2603,7 +2603,8 @@ void edit_draw(filestruct *fileptr, const char *converted, int /* If the found start has been qualified as an end earlier, * believe it and skip to the next step. */ if (start_line != NULL && start_line->multidata != NULL && - start_line->multidata[tmpcolor->id] == CBEGINBEFORE) + (start_line->multidata[tmpcolor->id] == CBEGINBEFORE || + start_line->multidata[tmpcolor->id] == CSTARTENDHERE)) goto step_two; /* Skip over a zero-length regex match. */ @@ -2678,8 +2679,9 @@ void edit_draw(filestruct *fileptr, const char *converted, int if (paintlen < 0) goto end_of_loop; step_two: - /* Second step, we look for starts on this line. */ - start_col = 0; + /* Second step: look for starts on this line, but start + * looking only after an end match, if there is one. */ + start_col = (paintlen == 0) ? 0 : endmatch.rm_eo; while (start_col < endpos) { if (regexec(tmpcolor->start, fileptr->data + @@ -2728,6 +2730,7 @@ void edit_draw(filestruct *fileptr, const char *converted, int #endif } } + start_col = endmatch.rm_eo; } else { /* There is no end on this line. But we * haven't yet looked for one on later @@ -2753,8 +2756,8 @@ void edit_draw(filestruct *fileptr, const char *converted, int fileptr->multidata[tmpcolor->id] = CENDAFTER; break; } + start_col = startmatch.rm_so + 1; } - start_col = startmatch.rm_so + 1; } } } -- 2.39.5