From owner-freebsd-standards Wed Mar 27 6:10:12 2002 Delivered-To: freebsd-standards@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 74A4637B41A for ; Wed, 27 Mar 2002 06:10:03 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g2REA3l38144; Wed, 27 Mar 2002 06:10:03 -0800 (PST) (envelope-from gnats) Date: Wed, 27 Mar 2002 06:10:03 -0800 (PST) Message-Id: <200203271410.g2REA3l38144@freefall.freebsd.org> To: freebsd-standards@FreeBSD.org Cc: From: Stefan Farfeleder Subject: Re: standards/36191: P1003.1-2001 csplit utility Reply-To: Stefan Farfeleder Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG The following reply was made to PR standards/36191; it has been noted by GNATS. From: Stefan Farfeleder To: "Tim J. Robbins" 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