From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,8083a431078ea083 X-Google-Attributes: gid1164f8,public From: strange@zk3.dec.com (Steve Strange USG) Subject: Re: Segmentation Violation Date: 1996/11/06 Message-ID: #1/1 X-Deja-AN: 194941717 references: <55qgbj$tdi@pulp.ucs.ualberta.ca> organization: Digital Equipment Corp. newsgroups: comp.sys.dec In article <55qgbj$tdi@pulp.ucs.ualberta.ca> nbehzad@ee.ualberta.ca (Nader Behzad) writes: > Hi all, > > Could anyone tell me if I am doing something wrong here or is it > the compiler: > i = (char_count - strlen(tempstring)); /* <-------- A */ > "tempstring" is NULL and this causes the program to crash at point A. > The strlen result for NULL should be 0 right?? > I don't have this problem under SUN_OS or Solaris platforms. I assume you're talking about Digital UNIX here. >From the strlen(3) manpage: Note If you pass a NULL pointer as the const char * parameter to the strlen function, the function generates a segmentation violation. To avoid the segmentation violation and cause the function to return 0 (zero), change the NULL pointer treatment for the process before issuing the call to the strlen function, as follows: 1. Include the system header file sys/uswitch.h. 2. Call the uswitch function, as described in the uswitch(3) reference page. The following program illustrates this procedure: #include #include #include main() { size_t retval; int uswitch_val; uswitch_val = uswitch(USC_GET,0); uswitch(USC_SET, uswitch_val | USW_NULLP); retval = strlen(NULL); Hope this helps. Steve -- Steve Strange strange@zk3.dec.com Digital Equipment Corporation, Nashua, NH (603) 881-0595 Digital UNIX Filesystem Development -- DCE DFS