Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 Nov 1995 17:30:35 +0100 (MET)
From:      grog@lemis.de (Greg Lehey)
To:        alexis@ww.net
Cc:        hackers@freebsd.org (FreeBSD Hackers)
Subject:   Re: index() doesn't handle NULL strings
Message-ID:  <199511151630.RAA27309@allegro.lemis.de>
In-Reply-To: <199511150836.LAA00686@unicorn.ww.net> from "Alexis Yushin" at Nov 15, 95 11:36:44 am

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199511151630.RAA27309>