Segmentation fault?

Brandon S. Allbery KB8JRR allbery at NCoast.ORG
Sun Mar 3 10:43:25 AEST 1991


As quoted from <944 at caslon.cs.arizona.edu> by dave at 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 at 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



More information about the Comp.unix.programmer mailing list