From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 30040 invoked from network); 19 May 2020 19:53:05 -0000 Received: from minnie.tuhs.org (45.79.103.53) by inbox.vuxu.org with ESMTPUTF8; 19 May 2020 19:53:05 -0000 Received: by minnie.tuhs.org (Postfix, from userid 112) id D10AF9C76D; Wed, 20 May 2020 05:53:02 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id A58D49C6B1; Wed, 20 May 2020 05:52:34 +1000 (AEST) Received: by minnie.tuhs.org (Postfix, from userid 112) id 15BB19C6B1; Wed, 20 May 2020 05:52:31 +1000 (AEST) X-Greylist: delayed 411 seconds by postgrey-1.36 at minnie.tuhs.org; Wed, 20 May 2020 05:52:30 AEST Received: from nimbus.fccf.net (nimbus.fccf.net [185.117.82.79]) by minnie.tuhs.org (Postfix) with ESMTPS id 2C3DD93D53 for ; Wed, 20 May 2020 05:52:30 +1000 (AEST) Received: from straylight.m.ringlet.net (unknown [93.152.146.108]) by nimbus.fccf.net (Postfix) with ESMTPSA id 39DC144E for ; Tue, 19 May 2020 22:45:36 +0300 (EEST) Received: from roam (uid 1000) (envelope-from roam@ringlet.net) id 6200e2 by straylight.m.ringlet.net (DragonFly Mail Agent v0.12); Tue, 19 May 2020 22:45:34 +0300 Date: Tue, 19 May 2020 22:45:34 +0300 From: Peter Pentchev To: Warner Losh Message-ID: <20200519194534.GH140052@straylight.m.ringlet.net> References: <202005141841.04EIfvEZ063529@tahoe.cs.Dartmouth.EDU> <20200515150122.GF30160@mcvoy.com> <014001d62af3$9cc209b0$d6461d10$@ronnatalie.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="FYos7FMnk2wAe7eG" Content-Disposition: inline In-Reply-To: Subject: Re: [TUHS] v7 K&R C X-BeenThere: tuhs@minnie.tuhs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: The Unix Heritage Society mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: The Eunuchs Hysterical Society Errors-To: tuhs-bounces@minnie.tuhs.org Sender: "TUHS" --FYos7FMnk2wAe7eG Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, May 16, 2020 at 11:39:54AM -0600, Warner Losh wrote: > On Sat, May 16, 2020 at 10:28 AM Paul Winalski > wrote: >=20 > > > On Fri, May 15, 2020 at 4:02 PM wrote: > > > > > >Unfortunately, if c is char on a machine with unsigned chars, or it=E2= =80=99s of > > >type unsigned char, the EOF will never be detected. > > > > > > - while ((c =3D getchar()) !=3D EOF) if (c =3D=3D '\n') { /* entir= e record is > > now there */ > > > > The function prototype for getchar() is: int getchar(void); > > > > It returns an int, not a char. In all likelihood this is specifically > > *because* EOF is defined as -1. The above code works fine if c is an > > int. One always has to be very careful when doing a typecast of a > > function return value. > > >=20 > In the early days of my involvement with FreeBSD, I went through and fixed > about a dozen cases where getopt was being assigned to a char and then > compared with EOF. I'm certain that this is why. Also EOF has to be a val= ue > that's not representable by a character, or your 0xff bytes would disappe= ar. I think I remember a code review on one of my patches to du(1), I think, something about adding an option to ignore specific names when recursing, and I remember either you or BDE chastising me about while (ch =3D getopt(...), ch !=3D EOF) :) G'luck, Peter --=20 Peter Pentchev roam@ringlet.net roam@debian.org pp@storpool.com PGP key: http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint 2EE7 A7A5 17FC 124C F115 C354 651E EFB0 2527 DF13 --FYos7FMnk2wAe7eG Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEELuenpRf8EkzxFcNUZR7vsCUn3xMFAl7EN1kACgkQZR7vsCUn 3xP7Qw//bNfN++zqFLi0jUnLq7ILgK07/DKzIsYEKy4G6dV6DDHcew3QJewySEPK v6pdqMjGdZp/MTxlWSS0FZljqSr1AbpA/MpAywEWYerhcPb/EcdTiBKi/2bVQjVy v7Xqwf2sEkqoFiwMjHGeG2aW68lXYBDaLQuNKwYR0tZXj7Hnh+jhb3TikTlxLoEQ GSLozFTOV3s7s8MqpK8FGkXq3dr8vQEtAFtakhbNn5ItshGV6g15Zr3EoAQzxXC8 gf3VC1mnB3CFFQoVCDwv5fj4I5e9aSv+8W8chi2sHS1JgZ5GuFK9imQQP/tvFxS1 lC7dtM4cu1UT4wEIfBmlQFMb7GqmypE9IeBrmPlVDw1az7P9uSBE4siUN9KO+qHZ NPWRp4S2knDzpVQok9PNJUSneABm8JQk90cPfs5axrPCztjmYVdhtqbD4GwKhLH6 ec/HNrtdT3iVGDk6aHNt8RtwFE7dKcxXc7J12pqTVmzmO6kRYwH02WaJGsb8UylV Iog6XQeSYSHePyuMVBEPULd8osEUdbVpErtXerRFNXmErBmhVJVxjF44zPVmYcn0 SakI0jFaekeaiwb9lkwZwRGfs3etxIzFggnDa2SPpiv+O4aNH9t8N6XundJS1SLE U/JJHRtIYc08HGMcbM95FN7S/2OeQfRC9c5wRT7+RpUhGdPU/bg= =WSaw -----END PGP SIGNATURE----- --FYos7FMnk2wAe7eG--