From owner-freebsd-arch Mon Feb 26 9: 5:47 2001 Delivered-To: freebsd-arch@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id 5276537B491 for ; Mon, 26 Feb 2001 09:05:43 -0800 (PST) (envelope-from bde@zeta.org.au) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id EAA29238; Tue, 27 Feb 2001 04:05:36 +1100 Date: Tue, 27 Feb 2001 04:05:34 +1100 (EST) From: Bruce Evans X-Sender: bde@besplex.bde.org To: "Kenneth D. Merry" Cc: arch@FreeBSD.ORG Subject: Re: sbufs in userland In-Reply-To: <20010226003319.A19994@panzer.kdm.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Mon, 26 Feb 2001, Kenneth D. Merry wrote: > ... > I would like to use the sbuf(9) interface to do the string formatting, > since it is fairly superior to my current string formatting method (see > scsi_sense_string() in sys/cam/scsi/scsi_all.c). > ... > Code without sbufs: > > switch (error_code) { > case SSD_DEFERRED_ERROR: > retlen = snprintf(tmpstr, tmpstrlen, "Deferred Error: "); > > if ((tmplen = str_len - cur_len - 1) < 0) > goto sst_bailout; > > strncat(str, tmpstr, tmplen); > cur_len += retlen; > str[str_len - 1] = '\0'; > /* FALLTHROUGH */ This seems to be insufficiently large to be correct :-). It doesn't check for snprintf failing (retlen == -1) or truncating (retlen >= tmpstrlen). > > Code with sbufs: > > switch (error_code) { > case SSD_DEFERRED_ERROR: > sbuf_printf(sb, "Deferred Error: "); > > /* FALLTHROUGH */ Code with an funopen(3)'d stream: switch (error_code) { case SSD_DEFERRED_ERROR: fprintf(fp, "Deferred Error: "); /* FALLTHROUGH */ :-). funopen() is more general than sbufs, so it is not quite as easy to use, but I think it is easy enough. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message