Date: Sun, 12 Jan 1997 14:49:57 -0700 (MST) From: Terry Lambert <terry@lambert.org> To: joerg_wunsch@uriah.heep.sax.de Cc: hackers@FreeBSD.org Subject: Re: number of lines in a file, given its size Message-ID: <199701122149.OAA26408@phaeton.artisoft.com> In-Reply-To: <Mutt.19970112214937.j@uriah.heep.sax.de> from "J Wunsch" at Jan 12, 97 09:49:37 pm
next in thread | previous in thread | raw e-mail | index | archive | help
> > > 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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199701122149.OAA26408>