fdopendir prototype on 7.3-RELEASE amd64
Sergey Kandaurov
pluknet at gmail.com
Wed Jun 1 17:38:54 UTC 2011
On 1 June 2011 19:27, Klaus T. Aehlig <aehlig at 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) {
> DIR *dirp;
> int fd;
>
> fd = open(".", O_RDONLY);
> dirp = fdopendir(fd);
> (void) readdir(dirp);
>
> }
>
> Compiling gives the warning "assignment makes pointer from integer without a cast"
> refering to the line with the fdopendir call. Indeed, adding the prototype
>
> extern DIR *fdopendir(int);
>
> right after the #include lines solves this problem. Is my understanding of 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-STABLE amd64.
Can you recheck it for 8.1? It should not be so.
--
wbr,
pluknet
More information about the freebsd-hackers
mailing list