From owner-freebsd-hackers Sun Jan 12 14:01:44 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id OAA26474 for hackers-outgoing; Sun, 12 Jan 1997 14:01:44 -0800 (PST) Received: from phaeton.artisoft.com (phaeton.Artisoft.COM [198.17.250.211]) by freefall.freebsd.org (8.8.4/8.8.4) with SMTP id OAA26466 for ; Sun, 12 Jan 1997 14:01:39 -0800 (PST) Received: (from terry@localhost) by phaeton.artisoft.com (8.6.11/8.6.9) id OAA26408; Sun, 12 Jan 1997 14:49:57 -0700 From: Terry Lambert Message-Id: <199701122149.OAA26408@phaeton.artisoft.com> Subject: Re: number of lines in a file, given its size To: joerg_wunsch@uriah.heep.sax.de Date: Sun, 12 Jan 1997 14:49:57 -0700 (MST) Cc: hackers@FreeBSD.org In-Reply-To: from "J Wunsch" at Jan 12, 97 09:49:37 pm X-Mailer: ELM [version 2.4 PL24] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@FreeBSD.org X-Loop: FreeBSD.org Precedence: bulk > > > But you've got your point wrong. strdup(), as much you prefer it or > > > not, was _by no means_ the answer to the question. The question was > > > You were the one concerned with the fixed buffer size (apparently as > > a means of an unlikely stack overflow attack). > > Yes. But Terry, you totally missed the point here, i'm telling you > for the third time now. I stop telling you this. Go, and read the > code! > > You can't allocate an array of pointers with strdup(). Period. Ah... I see; never mind. I think erroring out to "okshells" on the malloc failure is a bit bogus... Wouldn'tr it be better to allocate the full file size, and strtok the \n's to nulls, and terminate with a double null instead? That way, you could pass back a pointer to a linear list. There's no reason initshells() has to pass back any particular type; after all, it's a static (internal use only) function. Probably the shell list is abstracted at the wrong level, causing the need for the pointer list? After all, a cast of the list should work, since they will be allocated contiguously... I guess you would still need to double-terminate the "okshells" list, though... Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.