nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nano-devel] Fixes for 1.3.11


From: David Lawrence Ramsey
Subject: Re: [Nano-devel] Fixes for 1.3.11
Date: Thu, 18 May 2006 09:19:43 -0400
User-agent: Thunderbird 1.5.0.2 (X11/20060420)

Jordi Mallach wrote:
> Hi list,
>
> David, due to being totally busy with a zillion different things
> around here, I've been neglecting nano email a little bit.

No problem.

> Ubuntu is about to release a new version in about 10 days, and I know
> the nano included is not as good as it could be. Right now, they have
> 1.3.10 + a few patches like the infamous segfault bug. I've got
> permission to change it to 1.3.11, as the changes are not dangerous
> and the fixes are good to have, and it's proved to be very stable in
> Debian.

That's good.

> Right now, Debian has nano 1.3.11 + the crontab editing patch, but I
> know I could use a few more. The telnet thing comes to mind, but what
> else?

The telnet thing doesn't apply to 1.3.11, since the bracket matching key
was temporarily changed to Ctrl-] only in 1.3.11-cvs.

> What patches would you really like to see in a stable ubuntu release
> with nano 1.3.11?

Three patches in particular.  (Thanks in advance.)

First, I've improved the crontab editing patch a bit after applying to
to CVS awhile ago.  Prepending when the original file is unreadable is
handled more consistently, and, as a side effect, prepending in
nano-tiny works again.  Unfortunately, I don't know exactly when it was
broken.  The attached nano1311backupfix.patch will fix this.

Second, the fix for segfaults with zero-length multi-line regexes is
important, seeing as segfaults with zero-length single-line regexes have
been fixed for ages.  The attached nano1311regexfix.patch will fix this.

Third, the ability to override regexes in the global nanorc with regexes
in the local nanorc without error messages is important, seeing as nano
could do that until recently (1.3.9).  The attached nano1311parse.patch
will fix this.

diff -ur nano-1.3.11/src/files.c nano-1.3.11-fixed/src/files.c
--- nano-1.3.11/src/files.c     2006-02-24 14:38:20.000000000 -0500
+++ nano-1.3.11-fixed/src/files.c       2006-05-18 08:59:47.000000000 -0400
@@ -1336,7 +1336,10 @@
                statusbar(_("Error reading %s: %s"), realname,
                        strerror(errno));
                beep();
-               goto cleanup_and_exit;
+               /* If we can't read from the original file, go on, since
+                * only saving the original file is better than saving
+                * nothing. */
+               goto skip_backup;
            }
        }
 
@@ -1375,8 +1378,10 @@
                    _("Too many backup files?"));
                free(backuptemp);
                free(backupname);
-               fclose(f);
-               goto cleanup_and_exit;
+               /* If we can't write to the backup, go on, since only
+                * saving the original file is better than saving
+                * nothing. */
+               goto skip_backup;
            } else {
                free(backupname);
                backupname = backuptemp;
@@ -1398,8 +1403,9 @@
            free(backupname);
            if (backup_file != NULL)
                fclose(backup_file);
-           fclose(f);
-           goto cleanup_and_exit;
+           /* If we can't write to the backup, go on, since only saving
+            * the original file is better than saving nothing. */
+           goto skip_backup;
        }
 
 #ifdef DEBUG
@@ -1414,7 +1420,6 @@
                openfile->current_stat->st_uid,
                openfile->current_stat->st_gid) == -1 ||
                utime(backupname, &filetime) == -1) {
-           free(backupname);
            if (copy_status == -1) {
                statusbar(_("Error reading %s: %s"), realname,
                        strerror(errno));
@@ -1422,11 +1427,15 @@
            } else
                statusbar(_("Error writing %s: %s"), backupname,
                        strerror(errno));
-           goto cleanup_and_exit;
+           /* If we can't read from or write to the backup, go on,
+            * since only saving the original file is better than saving
+            * nothing. */
        }
 
        free(backupname);
     }
+
+  skip_backup:
 #endif /* !NANO_TINY */
 
     /* If NOFOLLOW_SYMLINKS is set and the file is a link, we aren't
@@ -1454,6 +1463,17 @@
        int fd_source;
        FILE *f_source = NULL;
 
+       if (f == NULL) {
+           f = fopen(realname, "rb");
+
+           if (f == NULL) {
+               statusbar(_("Error reading %s: %s"), realname,
+                       strerror(errno));
+               beep();
+               goto cleanup_and_exit;
+           }
+       }
+
        tempname = safe_tempfile(&f);
 
        if (tempname == NULL) {
diff -ur nano-1.3.11/src/winio.c nano-1.3.11-fixed/src/winio.c
--- nano-1.3.11/src/winio.c     2006-03-29 20:18:29.000000000 -0500
+++ nano-1.3.11-fixed/src/winio.c       2006-05-08 12:38:16.000000000 -0400
@@ -2383,10 +2383,8 @@
                                _("Refusing zero-length regex match"));
                    } else if (startmatch.rm_so < endpos &&
                        startmatch.rm_eo > startpos) {
-                       if (startmatch.rm_so <= startpos)
-                           x_start = 0;
-                       else
-                           x_start = strnlenpt(fileptr->data,
+                       x_start = (startmatch.rm_so <= startpos) ? 0 :
+                               strnlenpt(fileptr->data,
                                startmatch.rm_so) - start;
 
                        index = actual_x(converted, x_start);
@@ -2430,129 +2428,135 @@
                        goto step_two;
                    start_line = start_line->prev;
                }
-               /* No start found, so skip to the next step. */
-               if (start_line == NULL)
-                   goto step_two;
-               /* Now start_line is the first line before fileptr
-                * containing a start match.  Is there a start on this
-                * line not followed by an end on this line? */
-               start_col = 0;
-               while (TRUE) {
-                   start_col += startmatch.rm_so;
-                   startmatch.rm_eo -= startmatch.rm_so;
-                   if (regexec(tmpcolor->end, start_line->data +
-                       start_col + startmatch.rm_eo, 0, NULL,
-                       (start_col + startmatch.rm_eo == 0) ? 0 :
-                       REG_NOTBOL) == REG_NOMATCH)
-                       /* No end found after this start. */
-                       break;
-                   start_col++;
-                   if (regexec(tmpcolor->start, start_line->data +
-                       start_col, 1, &startmatch,
-                       REG_NOTBOL) == REG_NOMATCH)
-                       /* No later start on this line. */
+               if (startmatch.rm_so == startmatch.rm_eo) {
+                   startmatch.rm_eo++;
+                   statusbar(_("Refusing zero-length regex match"));
+               } else {
+                   /* No start found, so skip to the next step. */
+                   if (start_line == NULL)
                        goto step_two;
-               }
-               /* Indeed, there is a start not followed on this line by
-                * an end. */
+                   /* Now start_line is the first line before fileptr
+                    * containing a start match.  Is there a start on
+                    * this line not followed by an end on this line? */
+                   start_col = 0;
+                   while (TRUE) {
+                       start_col += startmatch.rm_so;
+                       startmatch.rm_eo -= startmatch.rm_so;
+                       if (regexec(tmpcolor->end, start_line->data +
+                               start_col + startmatch.rm_eo, 0, NULL,
+                               (start_col + startmatch.rm_eo == 0) ?
+                               0 : REG_NOTBOL) == REG_NOMATCH)
+                           /* No end found after this start. */
+                           break;
+                       start_col++;
+                       if (regexec(tmpcolor->start, start_line->data +
+                               start_col, 1, &startmatch,
+                               REG_NOTBOL) == REG_NOMATCH)
+                           /* No later start on this line. */
+                           goto step_two;
+                   }
+                   /* Indeed, there is a start not followed on this
+                    * line by an end. */
 
-               /* We have already checked that there is no end before
-                * fileptr and after the start.  Is there an end after
-                * the start at all?  We don't paint unterminated
-                * starts. */
-               end_line = fileptr;
-               while (end_line != NULL && regexec(tmpcolor->end,
+                   /* We have already checked that there is no end
+                    * before fileptr and after the start.  Is there an
+                    * end after the start at all?  We don't paint
+                    * unterminated starts. */
+                   end_line = fileptr;
+                   while (end_line != NULL && regexec(tmpcolor->end,
                        end_line->data, 1, &endmatch, 0) == REG_NOMATCH)
-                   end_line = end_line->next;
+                       end_line = end_line->next;
 
-               /* No end found, or it is too early. */
-               if (end_line == NULL || (end_line == fileptr &&
+                   /* No end found, or it is too early. */
+                   if (end_line == NULL || (end_line == fileptr &&
                        endmatch.rm_eo <= startpos))
-                   goto step_two;
+                       goto step_two;
 
-               /* Now paint the start of fileptr. */
-               if (end_line != fileptr)
-                   /* If the start of fileptr is on a different line
-                    * from the end, paintlen is -1, meaning that
-                    * everything on the line gets painted. */
-                   paintlen = -1;
-               else
-                   /* Otherwise, paintlen is the expanded location of
-                    * the end of the match minus the expanded location
-                    * of the beginning of the page. */
-                   paintlen = actual_x(converted,
-                       strnlenpt(fileptr->data, endmatch.rm_eo) -
-                       start);
+                   /* Now paint the start of fileptr. */
+                   if (end_line != fileptr)
+                       /* If the start of fileptr is on a different
+                        * line from the end, paintlen is -1, meaning
+                        * that everything on the line gets painted. */
+                       paintlen = -1;
+                   else
+                       /* Otherwise, paintlen is the expanded location
+                        * of the end of the match minus the expanded
+                        * location of the beginning of the page. */
+                       paintlen = actual_x(converted,
+                               strnlenpt(fileptr->data,
+                               endmatch.rm_eo) - start);
 
-               mvwaddnstr(edit, line, 0, converted, paintlen);
+                   mvwaddnstr(edit, line, 0, converted, paintlen);
 
   step_two:
-               /* Second step, we look for starts on this line. */
-               start_col = 0;
+                   /* Second step, we look for starts on this line. */
+                   start_col = 0;
 
-               while (start_col < endpos) {
-                   if (regexec(tmpcolor->start, fileptr->data +
-                       start_col, 1, &startmatch, (start_col == 0) ?
-                       0 : REG_NOTBOL) == REG_NOMATCH || start_col +
-                       startmatch.rm_so >= endpos)
-                       /* No more starts on this line. */
-                       break;
-                   /* Translate the match to be relative to the
-                    * beginning of the line. */
-                   startmatch.rm_so += start_col;
-                   startmatch.rm_eo += start_col;
+                   while (start_col < endpos) {
+                       if (regexec(tmpcolor->start, fileptr->data +
+                               start_col, 1, &startmatch, (start_col ==
+                               0) ? 0 : REG_NOTBOL) == REG_NOMATCH ||
+                               start_col + startmatch.rm_so >= endpos)
+                           /* No more starts on this line. */
+                           break;
+                       /* Translate the match to be relative to the
+                        * beginning of the line. */
+                       startmatch.rm_so += start_col;
+                       startmatch.rm_eo += start_col;
 
-                   if (startmatch.rm_so <= startpos)
-                       x_start = 0;
-                   else
-                       x_start = strnlenpt(fileptr->data,
+                       x_start = (startmatch.rm_so <= startpos) ? 0 :
+                               strnlenpt(fileptr->data,
                                startmatch.rm_so) - start;
 
-                   index = actual_x(converted, x_start);
+                       index = actual_x(converted, x_start);
 
-                   if (regexec(tmpcolor->end, fileptr->data +
-                       startmatch.rm_eo, 1, &endmatch,
-                       (startmatch.rm_eo == 0) ? 0 : REG_NOTBOL) ==
-                       0) {
-                       /* Translate the end match to be relative to the
-                        * beginning of the line. */
-                       endmatch.rm_so += startmatch.rm_eo;
-                       endmatch.rm_eo += startmatch.rm_eo;
-                       /* There is an end on this line.  But does it
-                        * appear on this page, and is the match more
-                        * than zero characters long? */
-                       if (endmatch.rm_eo > startpos &&
+                       if (regexec(tmpcolor->end, fileptr->data +
+                               startmatch.rm_eo, 1, &endmatch,
+                               (startmatch.rm_eo == 0) ? 0 :
+                               REG_NOTBOL) == 0) {
+                           /* Translate the end match to be relative to
+                            * the beginning of the line. */
+                           endmatch.rm_so += startmatch.rm_eo;
+                           endmatch.rm_eo += startmatch.rm_eo;
+                           /* There is an end on this line.  But does
+                            * it appear on this page, and is the match
+                            * more than zero characters long? */
+                           if (endmatch.rm_eo > startpos &&
                                endmatch.rm_eo > startmatch.rm_so) {
-                           paintlen = actual_x(converted + index,
-                               strnlenpt(fileptr->data,
-                               endmatch.rm_eo) - start - x_start);
-
-                           assert(0 <= x_start && x_start < COLS);
+                               paintlen = actual_x(converted + index,
+                                       strnlenpt(fileptr->data,
+                                       endmatch.rm_eo) - start -
+                                       x_start);
+
+                               assert(0 <= x_start && x_start < COLS);
+
+                               mvwaddnstr(edit, line, x_start,
+                                       converted + index, paintlen);
+                           }
+                       } else {
+                           /* There is no end on this line.  But we
+                            * haven't yet looked for one on later
+                            * lines. */
+                           end_line = fileptr->next;
 
-                           mvwaddnstr(edit, line, x_start, converted +
-                               index, paintlen);
-                       }
-                   } else {
-                       /* There is no end on this line.  But we haven't
-                        * yet looked for one on later lines. */
-                       end_line = fileptr->next;
-
-                       while (end_line != NULL &&
+                           while (end_line != NULL &&
                                regexec(tmpcolor->end, end_line->data,
                                0, NULL, 0) == REG_NOMATCH)
-                           end_line = end_line->next;
+                               end_line = end_line->next;
 
-                       if (end_line != NULL) {
-                           assert(0 <= x_start && x_start < COLS);
+                           if (end_line != NULL) {
+                               assert(0 <= x_start && x_start < COLS);
 
-                           mvwaddnstr(edit, line, x_start, converted +
-                               index, -1);
-                           /* We painted to the end of the line, so
-                            * don't bother checking any more starts. */
-                           break;
+                               mvwaddnstr(edit, line, x_start,
+                                       converted + index, -1);
+                               /* We painted to the end of the line, so
+                                * don't bother checking any more
+                                * starts. */
+                               break;
+                           }
                        }
+                       start_col = startmatch.rm_so + 1;
                    }
-                   start_col = startmatch.rm_so + 1;
                }
            }
 
diff -ur nano-1.3.11/src/rcfile.c nano-1.3.11-fixed/src/rcfile.c
--- nano-1.3.11/src/rcfile.c    2006-01-06 17:04:38.000000000 -0500
+++ nano-1.3.11-fixed/src/rcfile.c      2006-04-15 12:43:25.000000000 -0400
@@ -275,7 +275,7 @@
 void parse_syntax(char *ptr)
 {
     const char *fileregptr = NULL, *nameptr = NULL;
-    const syntaxtype *tmpsyntax;
+    syntaxtype *tmpsyntax;
     exttype *endext = NULL;
        /* The end of the extensions list for this syntax. */
 
@@ -300,11 +300,16 @@
     if (ptr == NULL)
        return;
 
+    /* Search for a duplicate syntax name.  If we find one, free it, so
+     * that we always use the last syntax with a given name. */
     for (tmpsyntax = syntaxes; tmpsyntax != NULL;
        tmpsyntax = tmpsyntax->next) {
        if (strcmp(nameptr, tmpsyntax->desc) == 0) {
-           rcfile_error(N_("Duplicate syntax name %s"), nameptr);
-           return;
+           syntaxtype *prev_syntax = tmpsyntax;
+
+           tmpsyntax = tmpsyntax->next;
+           free(prev_syntax);
+           break;
        }
     }
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]