From owner-freebsd-hackers Wed Nov 15 09:09:03 1995 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id JAA24513 for hackers-outgoing; Wed, 15 Nov 1995 09:09:03 -0800 Received: from cls.net (freeside.cls.de [192.129.50.1]) by freefall.freebsd.org (8.6.12/8.6.6) with SMTP id JAA24472 for ; Wed, 15 Nov 1995 09:08:47 -0800 Received: by mail.cls.net (Smail3.1.29.1) from allegro.lemis.de (192.109.197.134) with smtp id ; Wed, 15 Nov 95 17:08 GMT From: grog@lemis.de (Greg Lehey) Organisation: LEMIS, Schellnhausen 2, 36325 Feldatal, Germany Phone: +49-6637-919123 Fax: +49-6637-919122 Reply-To: grog@lemis.de (Greg Lehey) Received: (grog@localhost) by allegro.lemis.de (8.6.9/8.6.9) id RAA27309; Wed, 15 Nov 1995 17:30:36 +0100 Message-Id: <199511151630.RAA27309@allegro.lemis.de> Subject: Re: index() doesn't handle NULL strings To: alexis@ww.net Date: Wed, 15 Nov 1995 17:30:35 +0100 (MET) Cc: hackers@freebsd.org (FreeBSD Hackers) In-Reply-To: <199511150836.LAA00686@unicorn.ww.net> from "Alexis Yushin" at Nov 15, 95 11:36:44 am X-Mailer: ELM [version 2.4 PL23] MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Content-Length: 1906 Sender: owner-hackers@freebsd.org Precedence: bulk Alexis Yushin writes: > > Once Greg Lehey wrote: > [...] > >Alexis Yushin writes: > >> > >> Perhaps it is out-of-date, because I use FreeBSD-2.0.5, > >> but if it is not it should be fixed. I don't send the patch, it > >> is obvious. > > > >Not to me, I'm afraid. Must be too early in the morning. > > if(!p) { > return (char *)NULL; > } This is in the context index (char *p, int c), yes? It doesn't harm to be more explicit. > >> The idea is in the subject. I see that it may be > >> intended for faster operations, but such a check would help > >> portability. Even if not we should point out the fact in the > >> manual page. > > > >Sure, I see the idea, but that's about all. Do you mean null strings > >or a NULL pointer? What do you mean by "handle"? > > NULL pointer. Handle correctly means not dumping core (reading > data pointed with NULL pointer) This is an opinion. Jörg Wunsch described a different one yesterday. I agree with Jörg. Of course, you don't have to dump core--that depends on what your program decides to do with a SIGSEGV. > >index(3) is, of course, obsolescent, and should be replaced by > >strchr(3), which is defined by ANSI. The ANSI definition doesn't > >state what should be done if the string pointer is NULL. I think this > >is an error condition which should cause the program to SIGSEGV. > > That is what index(3) does. Hmmm, which index(3)? Do you know of any standard that says that this is correct? If so, it would mean that we are wrong in equating index() with strrchr(). I've been through this before in my System V days. We (Tandem) had similar complaints, but we stuck to our guns. Write bad systems software to compensate for bad software on top, and things just go from bad to worse. > Sorry for the delay which took place > in replying to your message. I was overloaded. You're welcome. Why should you be different? :-) Greg