Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site cyb-eng.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!ut-sally!cyb-eng!bc From: bc@cyb-eng.UUCP (Bill Crews) Newsgroups: net.lang.c Subject: Re: Need strnlen(). Message-ID: <786@cyb-eng.UUCP> Date: Wed, 20-Nov-85 09:02:41 EST Article-I.D.: cyb-eng.786 Posted: Wed Nov 20 09:02:41 1985 Date-Received: Sat, 23-Nov-85 01:48:05 EST References: <207@a.sei.cmu.edu> Organization: Cyb Systems, Austin, TX Lines: 20 > One should never allow a character array to not have a null terminating byte. > Doing things like this should be automatic. Besides, usually when the program > dumps core, one usually can find the problem readily. Also, if I am not > mistaken, having character arrays that do not have terminating null bytes > will cause problems with many other funtions e.g printf(). printf() (or > maybe _doprint() I'm not sure which) will keep printing characters until they > hit that null byte, but they probably won't find it where it should be. > Unless I'm wrong, making sure strings are null terminated should be as > automatic as making sure that you aren't trying to use NULL pointers or > that malloc() returns a valid pointer. It should be obvious that one is sometimes governed by external constraints, such as the format of a directory entry. If a file or directory entry format contains a fixed-length field which contains textual data that can fill the entire field, one must deal with it somehow. -- - bc - ..!{seismo,topaz,gatech,nbires,ihnp4}!ut-sally!cyb-eng!bc (512) 835-2266