🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #50284

Segmentation Fault

#50284
From: Frank Rustemeyer
Date: Sun, 31 Oct 1993 10:38
42 lines
1810 bytes
The following program does compile, but when i run it under UNIX it produces
a "segmenattion fault" after the return statement int main() is reached.
The code is standard ansi c, and i cannot find any errors.
If you have an explanation or a solution, please mail to
masc0827@rohan.sdsu.edu (Frank Rustemeyer). Thanks in advance.

-------------------------------------------------------------------------

/* Shortest program to produce the error.
// If any of the lines (1),(2),(3) are deleted, the error will not occur.
// In line (2),  it has no effect to use NULL, or 0 instead of
// (struct list *) 0. */

#include <stdio.h>
#include <malloc.h>


struct list               
{   int x;                                      /* (1) */
    int *line;
    struct list *nxt; 
    } ;                         

struct list *root;


void declare(void)
{   struct list *l;

    if (!(root = (struct list *) malloc(sizeof (struct list *))))
       return;
    l = root;              
    l->nxt = (struct list *) 0;                  /*  (2)  */
    } 

void nothing(void) { printf ("!\n");}

int main(void)
{   declare();
    nothing();                                   /*  (3)  */
    return 1;
    }
Technical Details
Message-ID: <2b04j6$iig@gondor.sdsu.edu>
Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!howland.reston.ans.net!usc!newshub.sdsu.edu!ucsnews!ucssun1.sdsu.edu.sdsu.edu!masc0827

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,774a836fafeb0c29,start
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1993-10-31 02:45:05 PST
Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!howland.reston.ans.net!usc!newshub.sdsu.edu!ucsnews!ucssun1.sdsu.edu.sdsu.edu!masc0827
From: masc0827@ucssun1.sdsu.edu (Frank Rustemeyer)
Newsgroups: gnu.gcc.help
Subject: Segmentation Fault
Date: 31 Oct 1993 10:38:30 GMT
Organization: SDSU Computing Services
Lines: 43
Distribution: gnu
Message-ID: <2b04j6$iig@gondor.sdsu.edu>
NNTP-Posting-Host: 130.191.1.100