From owner-freebsd-standards Fri Mar 22 19:50:22 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 DC58037B404 for ; Fri, 22 Mar 2002 19:50:07 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g2N3o7933719; Fri, 22 Mar 2002 19:50:07 -0800 (PST) (envelope-from gnats) Date: Fri, 22 Mar 2002 19:50:07 -0800 (PST) Message-Id: <200203230350.g2N3o7933719@freefall.freebsd.org> To: freebsd-standards@FreeBSD.org Cc: From: "Tim J. Robbins" Subject: Re: standards/36191: P1003.1-2001 csplit utility Reply-To: "Tim J. Robbins" 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: "Tim J. Robbins" To: "Brian F. Feldman" Cc: freebsd-gnats-submit@FreeBSD.org Subject: Re: standards/36191: P1003.1-2001 csplit utility Date: Sat, 23 Mar 2002 14:41:04 +1100 On Fri, Mar 22, 2002 at 09:49:36AM -0500, Brian F. Feldman wrote: > "Tim J. Robbins" wrote: > > X sprintf(fmt, "%%s%%0%ldld", sufflen); > > X sprintf(currfile, fmt, prefix, nfiles); > > This is a bit of a strange construct. You should probably be using > something like: > snprintf(currfile, sizeof(currfile), "%s%*ld", prefix, sufflen, nfiles); Thanks for your suggestion - that way is indeed much cleaner. --- csplit.c 2002/03/22 07:39:55 1.17 +++ csplit.c 2002/03/23 03:36:26 1.18 @@ -44,7 +44,7 @@ #include __FBSDID("$FreeBSD$"); -__RCSID("$Id: csplit.c,v 1.17 2002/03/22 07:39:55 tim Exp $"); +__RCSID("$Id: csplit.c,v 1.18 2002/03/23 03:36:26 tim Exp $"); #include @@ -91,11 +91,10 @@ FILE * newfile(void) { - char fmt[20]; FILE *fp; - sprintf(fmt, "%%s%%0%ldld", sufflen); - sprintf(currfile, fmt, prefix, nfiles); + snprintf(currfile, sizeof(currfile), "%s%0*ld", prefix, sufflen, + nfiles); if ((fp = fopen(currfile, "w+")) == NULL) err(1, "%s", currfile); nfiles++; @@ -107,15 +106,14 @@ void cleanup(void) { - char fmt[20], fnbuf[PATH_MAX]; + char fnbuf[PATH_MAX]; long i; if (!doclean) return; for (i = 0; i < nfiles; i++) { - sprintf(fmt, "%%s%%0%ldld", sufflen); - sprintf(fnbuf, fmt, prefix, i); + snprintf(fnbuf, sizeof(fnbuf), "%s%0*ld", prefix, sufflen, i); unlink(fnbuf); } } Tim To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message