NetBSD Problem Report #55527

From silas_netbsd_gnats@nocafe.net  Fri Jul 31 16:32:38 2020
Return-Path: <silas_netbsd_gnats@nocafe.net>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 36E231A9213
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 31 Jul 2020 16:32:38 +0000 (UTC)
Message-Id: <20200731163233.315D521C50@hope.nocafe.net>
Date: Fri, 31 Jul 2020 13:32:33 -0300 (-03)
From: silas_netbsd_gnats@nocafe.net
Reply-To: silas_netbsd_gnats@nocafe.net
To: gnats-bugs@NetBSD.org
Subject: incorrect output when -k is used and there are more patterns than matches
X-Send-Pr-Version: 3.95

>Number:         55527
>Category:       bin
>Synopsis:       incorrect output when -k is used and there are more patterns than matches
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jul 31 16:35:00 +0000 2020
>Originator:     silas_netbsd_gnats@nocafe.net
>Release:        NetBSD 8.2
>Organization:
>Environment:
>Description:
When csplit -k flag (which does not remove created files) and there are more
patterns than matches for a file, the file created before the last one has
incorrect output.

Although I'm using NetBSD 8.2, I tested CVS version (1.7) and the behaviour is
the same.
>How-To-Repeat:
cd /tmp
echo '
a:
b:
c:
d:' > test
csplit -k test '/.*:/' '{999}'

# File xx03 should have "c:" but it has "c:\nd:"
>Fix:

The following patch fix that, but I'm not familiar enough with the codebase to
be sure it doesn't break in other situation.

--- csplit.c.orig	2020-07-31 12:29:24.234981477 -0300
+++ csplit.c	2020-07-31 12:33:11.423349708 -0300
@@ -410,8 +410,10 @@
 		first = 0;
 	}

-	if (p == NULL)
+	if (p == NULL) {
+		toomuch(ofp, 1);
 		errx(1, "%s: no match", re);
+	}

 	if (ofs <= 0) {
 		/*

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.