delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/08/09:16:07

From: sparhawk AT eunet DOT at (Gerhard Gruber)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Segmentation fault in UNIX
Date: Fri, 08 May 1998 13:02:30 GMT
Organization: Customer of EUnet Austria
Lines: 45
Message-ID: <3553edeb.3391725@news.Austria.EU.net>
References: <35519D05 DOT 18BA AT cc DOT hut DOT fi>
NNTP-Posting-Host: e014.dynamic.vienna.at.eu.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Destination: Ville Lundberg <vlundber AT cc DOT hut DOT fi>
From: Gruber Gerhard
Group: comp.os.msdos.djgpp
Date: Thu, 07 May 1998 14:37:41 +0300:

>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.
>
>#include <stdio.h>
>#include <stdlib.h>
>#include <unistd.h>
>
>void main(void) {
>char *lin, *pin;
>
>do {
>  printf("Enter name and password:\n");
>  printf("Name:");
>  gets(lin);
>} while(strcmp(lin, "")==NULL);
>
>pin = getpass("Password:");
> 
>// And here's nothing more than opening a file and couple printf:s
>
>}

No memory allocated for lin and pin.

before you call gets() you have to have some line like 
if((lin = malloc(<len>)) == NULL)
{
	fprintf(stderr, "not enough memory\n");
    exit(1);
}

--
Bye,
   Gerhard

email: sparhawk AT eunet DOT at
       g DOT gruber AT sis DOT co DOT at

Spelling corrections are appreciated.

- Raw text -


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