From owner-freebsd-questions@FreeBSD.ORG Wed Mar 21 15:42:02 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id E58FA106566B for ; Wed, 21 Mar 2012 15:42:02 +0000 (UTC) (envelope-from erichfreebsdlist@ovitrap.com) Received: from alogreentechnologies.com (alogreentechnologies.com [67.212.226.44]) by mx1.freebsd.org (Postfix) with ESMTP id 8C6618FC14 for ; Wed, 21 Mar 2012 15:42:02 +0000 (UTC) Received: from amd620.ovitrap.com ([49.128.188.2]) (authenticated bits=0) by alogreentechnologies.com (8.13.1/8.13.1) with ESMTP id q2LFdeEc020638; Wed, 21 Mar 2012 09:40:14 -0600 From: Erich Dollansky To: freebsd-questions@freebsd.org Date: Wed, 21 Mar 2012 22:39:45 +0700 User-Agent: KMail/1.13.7 (FreeBSD/8.3-PRERELEASE; KDE/4.7.4; amd64; ; ) References: <201203211450.q2LEoPqM078354@dc.cis.okstate.edu> In-Reply-To: <201203211450.q2LEoPqM078354@dc.cis.okstate.edu> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201203212239.45479.erichfreebsdlist@ovitrap.com> Cc: Martin McCormick Subject: Re: Freebsd9.0 and the fgets directive in gcc X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Mar 2012 15:42:03 -0000 Hi, On Wednesday 21 March 2012 21:50:25 Martin McCormick wrote: > I've got some code which I wrote about 6 or 8 years ago that > apparently doesn't get along right now with FreeBSD9.0. In the > problem code, there is a loop that uses fgets to read a line > from a file. It runs properly until the 2708TH iteration and > then it dumps core with a segmentation fault. > > char string0[256]; > more lines of code . . . > > while ( fgets(string0,sizeof(string0),fp_config)) { how long is one line? Could it be that the failing line has 256 or more characters? I would use while ( fgets(string0,sizeof(string0) -1,fp_config)) { to make sure that the last character does not cause a buffer overrun, no matter what fgets is supposed to do. Erich