Path: utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!kate.mita.keio.ac.jp!kaz From: kaz@kate.mita.keio.ac.jp (Kazuhiro Kitagawa) Newsgroups: comp.soft-sys.andrew Subject: difference of strlen Message-ID: Date: 16 Oct 89 10:54:51 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 42 The bush program runs RT-PC correctly, but it does not run on Sun 3 sometime in paticular case. On Sun 3, it dumps core with Segment violation when searching the files with unknown uid. ---------bush.c --------------- static void AllocNameSpace( target, source ) char **target, *source; { if(!target) return; if(*target) free(*target); if(*target = malloc(strlen(source)+1)) strcpy(*target,source); } ------------------------------------------ The follwoing code includes bug. On RT-PC, strlen() dose not dumps core, if source is NULL, On Sun 3, strlen dumps core. Sometime AllocNameSpace is called as second arguement being NULL. Because of, on RT-PC users can read address 0 and it value is NULL, but, on Sun 3 we can not read address 0. This program(bush) should include the follwoing code at first line. static void AllocNameSpace( target, source ) char **target, *source; { if(!source)return if(!target) return; if(*target) free(*target); if(*target = malloc(strlen(source)+1)) strcpy(*target,source); } Kaz. Kitagawa Phd. Candidate KEIO Univ. Dept of math.