From owner-freebsd-arch Mon Dec 11 19:20:13 2000 From owner-freebsd-arch@FreeBSD.ORG Mon Dec 11 19:20:11 2000 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from netau1.alcanet.com.au (ntp.alcanet.com.au [203.62.196.27]) by hub.freebsd.org (Postfix) with ESMTP id 4DE7F37B400 for ; Mon, 11 Dec 2000 19:20:10 -0800 (PST) Received: from mfg1.cim.alcatel.com.au (mfg1.cim.alcatel.com.au [139.188.23.1]) by netau1.alcanet.com.au (8.9.3 (PHNE_18979)/8.9.3) with ESMTP id OAA16449; Tue, 12 Dec 2000 14:20:05 +1100 (EDT) Received: from gsmx07.alcatel.com.au by cim.alcatel.com.au (PMDF V5.2-32 #37645) with ESMTP id <01JXMBQO8JPCEAFV8Y@cim.alcatel.com.au>; Tue, 12 Dec 2000 14:19:55 +1100 Received: (from jeremyp@localhost) by gsmx07.alcatel.com.au (8.11.0/8.11.0) id eBC3JwY29509; Tue, 12 Dec 2000 14:19:58 +1100 (EST envelope-from jeremyp) Content-return: prohibited Date: Tue, 12 Dec 2000 14:19:58 +1100 From: Peter Jeremy Subject: Re: Safe string formatting in the kernel In-reply-to: ; from des@ofug.org on Mon, Dec 11, 2000 at 08:13:24PM +0100 To: Dag-Erling Smorgrav Cc: arch@FreeBSD.ORG Mail-followup-to: Dag-Erling Smorgrav , arch@FreeBSD.ORG Message-id: <20001212141958.P69646@gsmx07.alcatel.com.au> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-disposition: inline User-Agent: Mutt/1.2.5i References: Sender: jeremyp@gsmx07.alcatel.com.au Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On 2000-Dec-11 20:13:24 +0100, Dag-Erling Smorgrav wrote: > http://people.freebsd.org/~des/software/sbuf-20001211b.diff Overall the purpose of this isn't clear to me. It doesn't appear to have any real advantages over using the standard string functions. The main advantage I can see for having a proper set of string functions would be to support dynamic (growable) strings and sbuf uses a fixed size buffer. +struct sbuf { + char *s_buf; /* storage buffer */ + size_t s_size; /* size of storage buffer */ + size_t s_len; /* current length of string */ + int s_dynamic; /* storage buffer must be freed */ + int s_done; /* sbuf is finished and read-only */ + int s_flags; /* flags */ + struct sbuf *s_next; /* next in chain */ +}; The s_flags and s_next fields appear to be unused. What is their purpose? 2 int's (s_dynamic and s_done) to store 2 boolean values seems excessive. I agree that having a flags word is useful (even if there aren't currently any caller values for it). Once a flags field is defined, all the flags should go there. Also, I believe it would be better to have s_next adjacent to s_buf. (To avoid padding before s_next - though the struct in its current form will have 4 bytes of padding on the Alpha/IA64 anyway). + while (*ptr && s->s_len < s->s_size - 1) + s->s_buf[s->s_len++] = *ptr++; + s->s_buf[s->s_len] = '\0'; How about strlcpy()? Peter To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message