9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Nick Owens <mischief@offblast.org>
To: 9front@9front.org
Subject: Re: [9front] bug in sed
Date: Fri, 11 Jan 2019 05:10:19 -0800	[thread overview]
Message-ID: <CAH_zEu4CUeicUE+TN5NgtqHZjtF6YQAzb1JcyS+ZLJv6T2fMxg@mail.gmail.com> (raw)
In-Reply-To: <CAFSF3XN7jskraQYgwC3GjKG+MHRX7jK5AoKKBi-1_uuoEADGug@mail.gmail.com>

in sed.c:/^substitute, when g is set, sed begins doing
match/substitute in a loop. after a substitution it moves the pointer
into the current string (called 'loc2') forward and tries to match
again. however, when it attempts to match the regexp again, the regexp
library is unaware that the string to be matched is not the true
beginning of the line. thus the match for ^ always succeeds.

compare OpenBSD regexec and sed, which use a REG_NOTBOL flag to
indicate that ^ cannot match in subsequent matches

https://man.openbsd.org/man3/regex.3
https://github.com/openbsd/src/blob/master/usr.bin/sed/process.c#L334

On Fri, Jan 11, 2019 at 4:58 AM hiro <23hiro@gmail.com> wrote:
>
> here's another testcase without needing spaces
>
> cpu% cat > test
> asdfasdf
> xasdf
>  cpu% sed  's/^asdf//g' test
>
> xasdf
> cpu% ssam  's/^asdf//g' test
> asdf
> xasdf


  reply	other threads:[~2019-01-11 13:10 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-11  5:07 Sean Hinchee
2019-01-11  8:42 ` 有澤健治
2019-01-11 10:20   ` hiro
2019-01-11 10:22     ` hiro
2019-01-11 10:28       ` hiro
2019-01-11 10:35         ` hiro
2019-01-11 13:04           ` 有澤健治
2019-01-11 10:32     ` 有澤健治
2019-01-11 17:49     ` Sean Hinchee
2019-01-11 19:03       ` hiro
2019-01-11 10:55 ` Ethan Gardener
2019-01-11 11:19   ` hiro
2019-01-11 11:21     ` hiro
2019-01-11 12:39       ` hiro
2019-01-11 13:10         ` Nick Owens [this message]
2019-01-11 15:01         ` Stanley Lieber
2019-01-11 15:19           ` Eckard Brauer
2019-01-11 18:30       ` Ethan Gardener
2019-01-11 19:01         ` hiro
2019-01-11 21:11           ` Xiao-Yong Jin
2019-01-11 23:06 umbraticus
2019-01-11 23:29 ` hiro
2019-01-11 23:46 umbraticus
2019-01-11 23:45 ` Kurt H Maier
2019-01-11 23:52 ` Eckard Brauer
2019-01-11 23:49 umbraticus
2019-01-12  0:52 umbraticus
2019-01-12  0:58 ` Kurt H Maier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAH_zEu4CUeicUE+TN5NgtqHZjtF6YQAzb1JcyS+ZLJv6T2fMxg@mail.gmail.com \
    --to=mischief@offblast.org \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).