Author: pfg
Date: Tue Jun 28 03:11:07 2016
New Revision: 302244
URL: https://svnweb.freebsd.org/changeset/base/302244

Log:
  MFC r301138:
  sed(1): convert sed to use REG_STARTEND more explicitly.
  
  This is a followup to previous r302228, which only merged the
  incomplete r300684 causing a regression.
  
  Reported by:  mi
  PR:           209387
  Taken from:     openbsd-tech (Martijn van Duren)

Modified:
  stable/10/usr.bin/sed/process.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.bin/sed/process.c
==============================================================================
--- stable/10/usr.bin/sed/process.c     Tue Jun 28 00:37:34 2016        
(r302243)
+++ stable/10/usr.bin/sed/process.c     Tue Jun 28 03:11:07 2016        
(r302244)
@@ -384,7 +384,7 @@ substitute(struct s_command *cp)
                                        linenum, fname, cp->u.s->maxbref);
                }
        }
-       if (!regexec_e(re, s, 0, 0, 0, psl))
+       if (!regexec_e(re, ps, 0, 0, 0, psl))
                return (0);
 
        SS.len = 0;                             /* Clean substitute space. */
@@ -394,7 +394,7 @@ substitute(struct s_command *cp)
 
        do {
                /* Copy the leading retained string. */
-               if (n <= 1 && match[0].rm_so - le)
+               if (n <= 1 && (match[0].rm_so > le))
                        cspace(&SS, s, match[0].rm_so - le, APPEND);
 
                /* Skip zero-length matches right after other matches. */
@@ -415,8 +415,8 @@ substitute(struct s_command *cp)
                }
 
                /* Move past this match. */
-               s += (match[0].rm_eo - le);
-               slen -= (match[0].rm_eo - le);
+               s = ps + match[0].rm_eo;
+               slen = psl - match[0].rm_eo;
                le = match[0].rm_eo;
 
                /*
@@ -436,7 +436,8 @@ substitute(struct s_command *cp)
                } else
                        lastempty = 0;
 
-       } while (n >= 0 && slen >= 0 && regexec_e(re, ps, 0, 0, le, psl));
+       } while (n >= 0 && slen >= 0 &&
+           regexec_e(re, ps, REG_NOTBOL, 0, le, psl));
 
        /* Did not find the requested number of matches. */
        if (n > 1)
_______________________________________________
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"

Reply via email to