Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Mar 2002 06:10:03 -0800 (PST)
From:      Stefan Farfeleder <e0026813@stud3.tuwien.ac.at>
To:        freebsd-standards@FreeBSD.org
Subject:   Re: standards/36191: P1003.1-2001 csplit utility
Message-ID:  <200203271410.g2REA3l38144@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR standards/36191; it has been noted by GNATS.

From: Stefan Farfeleder <e0026813@stud3.tuwien.ac.at>
To: "Tim J. Robbins" <tim@robbins.dropbear.id.au>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: standards/36191: P1003.1-2001 csplit utility
Date: Wed, 27 Mar 2002 15:07:51 +0100

 This patch fixes/changes these things (based on rev 1.21):
 
 * Posix says: ``An error shall be reported if an operand does not
   reference a line between the current position and the end of the
   file.''
   csplit now reports "out of range" if EOF is found before the line it
   is looking for.
 
 * The computation of 10 ** sufflen does not used signed overflow.
 
 * There's a single call to ftell, all others are ftello. I think this
   was a typo.
 
 Issues to be resolved:
 
 * Posix requires removal of output files on SIGHUP, SIGINT and SIGTERM.
   A simple handler calling cleanup() would do this. [Is there any danger
   in calling snprintf() from a signal handler?]
 
 * I think a matching re on the very first line must create an empty file
   xx00.
 
 
 Stefan
 
 ---snip---
 
 --- csplit.c.orig	Wed Mar 27 13:53:45 2002
 +++ csplit.c	Wed Mar 27 14:41:07 2002
 @@ -250,6 +250,9 @@
  		first = 0;
  	}
  
 +	if (p == NULL)
 +		errx(1, "%s: out of range", expr);
 +
  	if (ofs <= 0) {
  		/*
  		 * Negative (or zero) offset: throw back any lines we should
 @@ -298,9 +301,12 @@
  
  	while (nfiles < maxfiles - 1) {
  		ofp = newfile();
 -		while (lineno + 1 != lastline)
 -			if ((p = getline()) == NULL || fputs(p, ofp) != 0)
 +		while (lineno + 1 != lastline) {
 +			if ((p = getline()) == NULL)
 +				errx(1, "%ld: out of range", lastline);
 +			if (fputs(p, ofp) != 0)
  				break;
 +		}
  		if (!sflag)
  			printf("%lld\n", (long long)ftello(ofp));
  		if (fclose(ofp) != 0)
 @@ -318,7 +324,7 @@
  	char *ep, *p;
  	FILE *ofp;
  	int ch;
 -	long i, n;
 +	long i;
  
  	kflag = sflag = 0;
  	prefix = "xx";
 @@ -371,11 +377,10 @@
  	overfile = NULL;
  
  	for (maxfiles = 1, i = 0; i < sufflen; i++) {
 -		n = maxfiles;
 -		maxfiles *= 10;
 -		if (maxfiles / 10 != n)
 +		if (maxfiles > LONG_MAX / 10)
  			errx(1, "%ld: suffix too long (limit %ld)",
  			    sufflen, i);
 +		maxfiles *= 10;
  	}
  
  	while (nfiles < maxfiles - 1 && (expr = *argv++) != NULL) {
 @@ -406,7 +411,7 @@
  		while ((p = getline()) != NULL && fputs(p, ofp) == 0)
  			;
  		if (!sflag)
 -			printf("%lld\n", (long long)ftell(ofp));
 +			printf("%lld\n", (long long)ftello(ofp));
  		if (fclose(ofp) != 0)
  			err(1, "%s", currfile);
  	}

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-standards" in the body of the message




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