www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/07/09:39:57

Date: Thu, 7 May 1998 16:37:18 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Ville Lundberg <vlundber AT cc DOT hut DOT fi>
cc: djgpp AT delorie DOT com
Subject: Re: Segmentation fault in UNIX
In-Reply-To: <35519D05.18BA@cc.hut.fi>
Message-ID: <Pine.SUN.3.91.980507163344.6703A-100000@is>
MIME-Version: 1.0

On Thu, 7 May 1998, Ville Lundberg wrote:

> Why does this simple piece of code cause a "Segmentation fault" in UNIX,
> while it works just fine in DOS? The error occurs when the code hits the
> getpass() function.

Your `line' variable points to nowhere, so your program dereferences am 
unitilialized pointer and crashes.

As to why doesn't it crash in DOS, it depends on your environment.  I 
think if you use CWSDPMI it will crash as well, but Windows doesn't 
usually care if you dereference null pointers.

> char *lin, *pin;

Either use "char lin[80]", or allocate memory dynamically with malloc, 
before you call gets(lin).

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019