Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83 (MC840302); site boring.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!mcvax!boring!jack From: jack@boring.UUCP Newsgroups: net.lang.c Subject: Re: Need strnlen(). Message-ID: <6691@boring.UUCP> Date: Fri, 15-Nov-85 20:13:55 EST Article-I.D.: boring.6691 Posted: Fri Nov 15 20:13:55 1985 Date-Received: Sun, 17-Nov-85 06:59:34 EST References: <207@a.sei.cmu.edu> Reply-To: jack@boring.UUCP (Jack Jansen) Organization: AMOEBA project, CWI, Amsterdam Lines: 19 Apparently-To: rnews@mcvax.LOCAL In article <207@a.sei.cmu.edu> dlc@a.sei.cmu.edu (Daryl Clevenger) writes: >One should never allow a character array to not have a null terminating byte. That's right, one *should* never allow it. On the other hand, if ou look at the format of /etc/utmp (v7, at least, dunno about 4.n or S5), there's 8 bytes available for loginnames, so if you've got an 8 char loginname, it won't be zero terminated. Or, look at the V7 directory entry for a 14-char filename. I *know* these should be avoided, but I would still prefer to see code like len = strnlen(buffer,BUFSIZ); above if( (len=strlen(buffer))>BUFSIZ) len=BUFSIZ; which will fail at some unknown point in the future, long after everyone who knew the code has passed away....... -- Jack Jansen, jack@mcvax.UUCP The shell is my oyster.