Subject: Re: A little program I wrote that core dumps. Should it?
To: RiscBSD Mailing List <port-arm32@NetBSD.ORG>
From: Peter Naulls <pnaulls@wave.co.nz>
List: port-arm32
Date: 06/16/1997 10:29:17
>
> void main(void) {
> FILE *f;
> f = fopen("/dev/lpt0");
> while (!feof(f)) putchar(fgetc(f));
> }
> cause a core dump after a little while?
You're not checking to see if f is void, which it will be
if you can't open /dev/lpt0, so there ends up being a
null pointer reference.
int main(void) {
FILE *f;
if ((f = fopen("/dev/lpt0")) {
while (!feof(f) putchar(fgetc(f));
}
return f == NULL;
}
--
+-----------------------------------------+-----------------------------------+
| Peter Naulls | Acorn Risc PC 700 *ARM Powered* |
| pnaulls@wave.co.nz | Porting Java & Sather for Risc OS |
| http://lucy.cs.waikato.ac.nz/~pnaulls/ | Co-editor of Acorn archive list |
| Phone 64-7-856-4562 | Computer consultancy |
| The meaning of life: 3.5 | Web page design |
+-----------------------------------------+-----------------------------------+
Senders of unsolicited email agree to send me NZ$100 for wasting my time