From owner-freebsd-hackers@FreeBSD.ORG Wed Jun 1 17:38:54 2011 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 9451D106566B for ; Wed, 1 Jun 2011 17:38:54 +0000 (UTC) (envelope-from pluknet@gmail.com) Received: from mail-qw0-f54.google.com (mail-qw0-f54.google.com [209.85.216.54]) by mx1.freebsd.org (Postfix) with ESMTP id 4A0D88FC15 for ; Wed, 1 Jun 2011 17:38:53 +0000 (UTC) Received: by qwc9 with SMTP id 9so27819qwc.13 for ; Wed, 01 Jun 2011 10:38:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=RbO9F38iR5Luq+Akz8BDvn2ecVdZ7OZLvPJ+TtjQDDw=; b=XNc+m0lJYqycU00TIaiAPX5z8dvpfP6OnSFKKinqCdLqCZqGNfQM/KfrDBrTqqKeAZ Q9bRWr1exkr2D1QVJ/LeKJ4LLkHulsqCPoR/Rben5HLgTcWuWfINrv9bSFLUArCi2XsU Fhwb88m2r/5AN2Lo/KqI01T14kJvInUe7jb/w= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=okAE5egtvaE24lzmfwHpkYBMFKnUHYHnzj9S6NkpsZOCbymhjzm+V1qW4p4etH+t86 5C1vu+oQeyebeoz0QpEHvB3kG9BOFYNl54xEsf+s35BY3/ESUeQt51J2qpj7Y/RH/Fgv UjooFukFAzRdw+MLn/6Vjewi7yNuBEAwVptSg= MIME-Version: 1.0 Received: by 10.229.67.218 with SMTP id s26mr5500598qci.40.1306948170089; Wed, 01 Jun 2011 10:09:30 -0700 (PDT) Received: by 10.229.86.133 with HTTP; Wed, 1 Jun 2011 10:09:30 -0700 (PDT) In-Reply-To: <20110601152713.GB51073@kta1c10.sesnet.soton.ac.uk> References: <20110601152713.GB51073@kta1c10.sesnet.soton.ac.uk> Date: Wed, 1 Jun 2011 21:09:30 +0400 Message-ID: From: Sergey Kandaurov To: "Klaus T. Aehlig" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: freebsd-hackers@freebsd.org Subject: Re: fdopendir prototype on 7.3-RELEASE amd64 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, 01 Jun 2011 17:38:54 -0000 On 1 June 2011 19:27, Klaus T. Aehlig wrote: > > [Please CC me, as I'm not subscribed to this list] > > Hallo, > > while dealing with PR ports/157274 [1], I found that the following > program cause a segmentation fault on 7.3-RELEASE amd64, even though > my understanding of the man page of fdopendir(3) says it should not. > > #include > #include > #include > > int main(int argc, char **argv) { > =A0DIR *dirp; > =A0int fd; > > =A0fd =3D open(".", O_RDONLY); > =A0dirp =3D fdopendir(fd); > =A0(void) readdir(dirp); > > } > > Compiling gives the warning "assignment makes pointer from integer withou= t a cast" > refering to the line with the fdopendir call. Indeed, adding the prototyp= e > > extern DIR *fdopendir(int); > > right after the #include lines solves this problem. Is my understanding o= f the > man page that the above #include lines should suffice incorrect? Is this > problem known---or even fixed already? That is because 7.3 mistakenly misses the fdopendir() declaration in dirent.h, though it is the first release from 7.x that ought to support it. That was fixed in 7.3-STABLE past 7.3 release. There should be no problem for any release from 8.x branch. Also, the description from manpage only says that the function has appeared in 8.0, and there's nothing about 7.x. A segmentation fault is indeed due to missing declaration. Here gcc assumes that a return type of fdopendir() is int, and truncates a return value to sizeof(int). [On amd64 a pointer is 64-bit capable, int is 32-bit capable. I guess that 7.3 i386 does not fail here, though it prints the warning.] > > I have reports that indicate that this problem also seems to exist on 7.3= -RELEASE-p4 amd64 > and 8.1-RELEASE i386. The above program does not segfault on my 8.2-STABL= E amd64. Can you recheck it for 8.1? It should not be so. --=20 wbr, pluknet