Date: Wed, 1 Jun 2011 21:09:30 +0400 From: Sergey Kandaurov <pluknet@gmail.com> To: "Klaus T. Aehlig" <aehlig@linta.de> Cc: freebsd-hackers@freebsd.org Subject: Re: fdopendir prototype on 7.3-RELEASE amd64 Message-ID: <BANLkTin=Js3V7TkUudZJWK9nQHY6U2C1-Q@mail.gmail.com> In-Reply-To: <20110601152713.GB51073@kta1c10.sesnet.soton.ac.uk> References: <20110601152713.GB51073@kta1c10.sesnet.soton.ac.uk>
next in thread | previous in thread | raw e-mail | index | archive | help
On 1 June 2011 19:27, Klaus T. Aehlig <aehlig@linta.de> 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 <fcntl.h> > #include <sys/types.h> > #include <dirent.h> > > 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BANLkTin=Js3V7TkUudZJWK9nQHY6U2C1-Q>