avoiding segmentation violation

avoiding segmentation violation

Post by Keith Michae » Wed, 25 Nov 1998 04:00:00



How do I check whether a pointer value will cause a segmentation
violation before using it?

--
 -------------------------------------------------------------
| Keith R. Michaels   Archival Evangelist                     |
| (425)865-6415       Boeing Archival Service (ufs.boeing.com)|
| Enterprise Servers, Technical Services, SSG.                |
 -------------------------------------------------------------

 
 
 

avoiding segmentation violation

Post by Marvin Wolftha » Sat, 28 Nov 1998 04:00:00


Use purify.


> How do I check whether a pointer value will cause a segmentation
> violation before using it?

> --
>  -------------------------------------------------------------
> | Keith R. Michaels   Archival Evangelist                     |
> | (425)865-6415       Boeing Archival Service (ufs.boeing.com)|
> | Enterprise Servers, Technical Services, SSG.                |
>  -------------------------------------------------------------

--
Marvin Wolfthal
Technical Director,
FSJ, Inc.


 
 
 

avoiding segmentation violation

Post by Andrew Gabri » Sat, 28 Nov 1998 04:00:00




Quote:>How do I check whether a pointer value will cause a segmentation
>violation before using it?

int validaddr(void *addr)
{
    static long pagemask = -1;
    char c;
    if (pagemask == -1)
        pagemask = ~(sysconf(_SC_PAGESIZE) - 1); /* initialise */

    addr = (void *)((long)addr & pagemask);  /* base of page */
    if (mincore((char *)addr, 1, &c) == -1 && errno == ENOMEM)
        return 0; /* invalid */
    else
        return 1; /* valid */

Quote:}

.
.
.

if (!validaddr(suspect_pointer))
     printf("Duff pointer %p\n", suspect_pointer);
.
.
.

[IIRC, this is based on something Casper posted a while back]

It won't tell you what type of accesses are permitted to the
address though.

--
Andrew Gabriel
Consultant Software Engineer

 
 
 

1. INIT: PANIC: segmentation violation! giving up..

I've been running Red Hat Linux 4.1 for several months now on my home
machine (AMD K6/233 w/48MB of Ram) without any problems.  Two days ago
we had a power blackout while I was in the middle of compile a new
kernel (ver 2.1.66).  Since then, linux dies during the boot process,
right after probing and properly identifying my hardware, including all
the hard disk partitions.  It prints the above error message (see the
subject line) and locks up solid.  The only way out is a hard reset.
Does anyone have any idea how to get aroud this.  I tried booting from
the boot floppy in 'rescue' mode to run fsck on my linux partitions.  It
found and corrected some problems.  Now all the partitions are 'clean'
but the system still dies at exactly the same point.  It will boot in
emergency mode (by typing 'linux emergency' at the lilo boot prompt) and
I'm able to look at both linux partitions (/root and /usr) and on the
surface they look just fine.  But, of course, in emergency mode, the
system's functionality is severely limited.  I'm starting to feel linux
withdrawal symptoms ;-) HELP!!!

--Max

2. EtherExpress Pro XMT problem?

3. Debuging Segmentation Violation Fault

4. How to restore a disk...does anyone know?

5. segmentation violation in ncurses

6. Help Solaris 2.7 CDE won't start on console

7. PANIC: INIT: segmentation violation ...

8. Help on pascal compiler for unix

9. segmentation violation

10. JDK 1.1.1 - segmentation violation

11. lpsfilt - Segmentation Violation

12. BUG: segmentation violation?

13. WordPerfect6/7 and libc (segmentation violations)