Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!agate!usenet.ins.cwru.edu!ncoast!allbery From: allbery@NCoast.ORG (Brandon S. Allbery KB8JRR) Newsgroups: comp.unix.programmer Subject: Re: Segmentation fault? Message-ID: <1991Mar3.004325.24521@NCoast.ORG> Date: 3 Mar 91 00:43:25 GMT References: <38192@netnews.upenn.edu> <944@caslon.cs.arizona.edu> Reply-To: allbery@ncoast.ORG (Brandon S. Allbery KB8JRR) Followup-To: comp.unix.programmer Organization: North Coast Public Access Un*x (ncoast) Lines: 18 As quoted from <944@caslon.cs.arizona.edu> by dave@cs.arizona.edu (Dave P. Schaumann): +--------------- | > if (fgets(line, BUFSIZ, fp) == NULL) | | Here is another, more subtle bug. fgets will write up to BUFSIZ characters | (in this call) to line. This is not including the final '\0' character. | The best thing to do is declare char line[BUFSIZ + 1], and all will be well. +--------------- fgets writes BUFSIZ-1 characters in all Unix and Unix-like systems I have encountered, specifically to leave room for the trailing \0. RTFM. ++Brandon -- Me: Brandon S. Allbery VHF/UHF: KB8JRR on 220, 2m, 440 Internet: allbery@NCoast.ORG Packet: KB8JRR @ WA8BXN America OnLine: KB8JRR AMPR: KB8JRR.AmPR.ORG [44.70.4.88] uunet!usenet.ins.cwru.edu!ncoast!allbery Delphi: ALLBERY