From owner-freebsd-hackers@FreeBSD.ORG Wed Mar 11 08:46:13 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5683110656C4 for ; Wed, 11 Mar 2009 08:46:13 +0000 (UTC) (envelope-from v.haisman@sh.cvut.cz) Received: from service1.sh.cvut.cz (service1.sh.cvut.cz [IPv6:2001:718:2::214]) by mx1.freebsd.org (Postfix) with ESMTP id D2F5E8FC19 for ; Wed, 11 Mar 2009 08:46:12 +0000 (UTC) (envelope-from v.haisman@sh.cvut.cz) Received: from localhost (localhost [127.0.0.1]) by service1.sh.cvut.cz (Postfix) with ESMTP id 1CF31123843; Wed, 11 Mar 2009 09:46:12 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at service1.sh.cvut.cz X-Spam-Score: -91.135 X-Spam-Level: X-Spam-Status: No, score=-91.135 tagged_above=-255 required=5 tests=[ALL_TRUSTED=-1.44, AWL=11.116, CRM114_HAM_00=, MISSING_HEADERS=0.189, SMTPAUTH_SHDOMAIN=-100] Received: from service1.sh.cvut.cz ([127.0.0.1]) by localhost (service1.sh.cvut.cz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jLqw-YyIM6PF; Wed, 11 Mar 2009 09:46:04 +0100 (CET) Received: from [192.168.1.2] (35.201.broadband4.iol.cz [85.71.201.35]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: v.haisman@sh.cvut.cz) by service1.sh.cvut.cz (Postfix) with ESMTP id 0737F12383C; Wed, 11 Mar 2009 09:46:03 +0100 (CET) Message-ID: <49B77A45.3000204@sh.cvut.cz> Date: Wed, 11 Mar 2009 09:45:57 +0100 From: =?UTF-8?B?VsOhY2xhdiBIYWlzbWFu?= User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) MIME-Version: 1.0 CC: freebsd-hackers@freebsd.org References: <49B6DC95.9070607@FreeBSD.org> In-Reply-To: <49B6DC95.9070607@FreeBSD.org> X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: Re: fgetc doubts X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Mar 2009 08:46:16 -0000 Gábor Kövesdán wrote, On 10.3.2009 22:33: > Hello, > > I have a problem when reading files with fgetc when a 0xff character > comes. In my code the reading stops at that point as if EOF had been > reached, but that's not actually the case. > The code is here: > http://p4web.freebsd.org/@md=d&cd=//&c=Nsd@//depot/projects/soc2008/gabor_textproc/grep/file.c?ac=64&rev1=40 You have a bug in the grep_fgetc() function in the BZIP case. Char type is signed on FreeBSD and you are sign extending the c variable in the "return (c)" statement. The line should read "return ((unsigned char)c)", if you want to model the function using the same semantics as C99 fgetc(). > > And the problem occurs in grep_fgetln() when the buffers is being filled > in: > for (; i < bufsiz && !grep_feof(f); i++) > binbuf[i] = grep_fgetc(f); > > Thanks in advance, > -- VH