Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 02 May 2017 23:48:23 +0000
From:      bugzilla-noreply@freebsd.org
To:        freebsd-bugs@FreeBSD.org
Subject:   [Bug 219024] [patch] csplit leaves last matching pattern at end of file N-1 as well as in file N
Message-ID:  <bug-219024-8@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D219024

            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: fbsd@opal.com
          Keywords: patch

Created attachment 182255
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D182255&action=
=3Dedit
[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 a=
re
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 - '/x=
xx/'
'{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.

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-219024-8>