Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: strange@zk3.dec.com (Steve Strange USG)
Subject: Re: Segmentation Violation
Date: 1996/11/06	[thread overview]
Message-ID: <STRANGE.96Nov6162303@wasted.dec.com> (raw)
In-Reply-To: 55qgbj$tdi@pulp.ucs.ualberta.ca


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 <stdio.h>
            #include <sys/types.h>
            #include <sys/uswitch.h>

            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



  parent reply	other threads:[~1996-11-06  5:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-11-06  5:00 Segmentation Violation Nader Behzad
1996-11-06  5:00 ` Ron Natalie
1996-11-06  5:00 ` Steve Strange USG [this message]
1996-11-06  5:00   ` Ron Natalie
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox