https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=219024

            Bug ID: 219024
           Summary: [patch] csplit leaves last matching pattern at end of
                    file N-1 as well as in file N
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Keywords: patch
          Severity: Affects Many People
          Priority: ---
         Component: bin
          Assignee: freebsd-bugs@FreeBSD.org
          Reporter: f...@opal.com
          Keywords: patch

Created attachment 182255
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=182255&action=edit
[patch] csplit.c

When using:
    csplit -k - '/patt/' '{count}'
with an input containing less than count lines matching patt, a logic error
causes the final pattern that matches to be left both at the start of file N
and also at the end of file N-1.  This is due to the fact that when there are
less than count matches, csplit will error when looking for another match.  In
that error condition, csplit simply prints a message and exits, rather than
calling its toomuch() function which is what truncates the previous output
file.

Repeat by:
    echo "one\ntwo\nxxx 1\nthree\nfour\nxxx 2\nfive\nsix" | csplit -k - '/xxx/'
'{10}'

Expected output:
xx00:
    one
    two

xx01:
    xxx 1
    three
    four

xx02:
    xxx 2
    five
    six

Actual output:
xx01:
    one
    two

xx02:
    xxx 1
    three
    four
    xxx 2

xx03:
    xxx 2
    five
    six

The "xxx 2" at the end of file xx02 is incorrect.  The attached patch fixes
this by making sure that toomuch() is called in the error case when a third
match is not found.

-- 
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
freebsd-bugs@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "freebsd-bugs-unsubscr...@freebsd.org"

Reply via email to