Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: hmm

From: Joe Greco <jgreco(at)solaria.sol.net>
Date: Wed Feb 19 1997 - 18:05:29 EST


> > char *p;
> >
> > if ((p = argv[0]) == NULL)
> > errx(2,"test: argc is zero");

Sanity check? I can't think of any cases where this would happen, but maybe some kernel god would correct me.

> It seems a bit strange to me. Just like the first part of the line

That's sort of obvious, at least in the context of the second part of the expression...

If you want to see if the last character in a string is '[', that is a very fast way to do it ( p[strlen(p) - 1] == '[' ). However, in the case where *p points to a zero-length string (i.e. argc[1] = ""), the expression evaluates to an invalid case: strlen(p) = 0, and 0 - 1 = -1. Taking the -1'th element of p[] is WRONG WRONG WRONG. But the ONLY time that this can happen is if you have a null string. So check for it first.

It's simply a test looking for an argument that ends with the character '['. It is precisely correct, with the assumption that p is a valid, non-NULL, null terminated string of some sort.

(Alternate way to think of it: If you have a zero length string, it obviously can not end in '[')

... Joe


Joe Greco - Systems Administrator			      jgreco@ns.sol.net
Solaria Public Access UNIX - Milwaukee, WI			   414/342-4847
Received on Wed Feb 19 15:05:46 1997
Do you need help?X

This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 12:41:02 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library