New submission from Max <[email protected]>:

$ gdb ffmpeg_g.exe
GNU gdb (GDB) 7.1
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show 
copying"
and "show warranty" for details.
This GDB was configured as "mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from c:\disk\ffmpeg-0.6.1\ffmpeg/ffmpeg_g.exe...done.
(gdb) run -v 9 -loglevel 99 -i rtsp://194.24.241.164/live.sdp?tcp -
acodec none -y video4.flv
Starting program: c:\disk\ffmpeg-0.6.1\ffmpeg/ffmpeg_g.exe -v 9 -
loglevel 99 -i rtsp://194.24.241.164/live.sdp?tcp -acod
ec none -y video4.flv
[New Thread 20848.0x26dc]
FFmpeg version git-8ed4cc6, Copyright (c) 2000-2011 the FFmpeg 
developers
  built on Feb 15 2011 18:27:37 with gcc 4.5.0
  configuration: --enable-memalign-hack --prefix=/c/disk/ffmpeg-
0.6.1/build --enable-gpl --enable-version3 --enable-nonf
ree
  libavutil    50. 37. 0 / 50. 37. 0
  libavcore     0. 16. 1 /  0. 16. 1
  libavcodec   52.113. 1 / 52.113. 1
  libavformat  52.100. 1 / 52.100. 1
  libavdevice  52.  2. 3 / 52.  2. 3
  libavfilter   1. 76. 0 /  1. 76. 0
  libswscale    0. 12. 0 /  0. 12. 0
[New Thread 20848.0x2b10]

Program received signal SIGSEGV, Segmentation fault.
0x77186395 in select () from C:\Windows\syswow64\ws2_32.dll

(gdb) bt
#0  0x77186395 in select () from C:\Windows\syswow64\ws2_32.dll
#1  0x00435231 in ff_freeaddrinfo (res=0x5b28) at 
libavformat/os_support.c:150
#2  0x004be4af in tcp_open (h=0x2bc31c0, uri=0x31dc <Address 0x31dc out 
of bounds>, flags=2) at libavformat/tcp.c:113
#3  0x00000fed in ?? ()
#4  0x02bc31c0 in ?? ()
#5  0x00000002 in ?? ()
#6  0x00000001 in ?? ()
#7  0x00000000 in ?? ()

It's occurs cause the select return not greatest fd number, but fd 
count.
man: On  success,  select()  and  pselect()  return  the number of file 
descriptors contained in the three returned descriptor sets (that is, 
the total number of bits that are set in readfds, writefds, exceptfds) 
which may  be zero  if  the timeout expires before anything interesting 
happens.

in second for loop must be in that form:

    for(i = 0; i < (nfds_t) numfds; i++) {
        ...
    }



All function:


int poll(struct pollfd *fds, nfds_t numfds, int timeout)
{
    fd_set read_set;
    fd_set write_set;
    fd_set exception_set;
    nfds_t i;
    int n;
    int rc;

#if HAVE_WINSOCK2_H
    if (numfds >= FD_SETSIZE) {
        errno = EINVAL;
        return -1;
    }
#endif

    FD_ZERO(&read_set);
    FD_ZERO(&write_set);
    FD_ZERO(&exception_set);

    n = -1;
    for(i = 0; i < numfds; i++) {
        if (fds[i].fd < 0)
            continue;
#if !HAVE_WINSOCK2_H
        if (fds[i].fd >= FD_SETSIZE) {
            errno = EINVAL;
            return -1;
        }
#endif

        if (fds[i].events & POLLIN)  FD_SET(fds[i].fd, &read_set);
        if (fds[i].events & POLLOUT) FD_SET(fds[i].fd, &write_set);
        if (fds[i].events & POLLERR) FD_SET(fds[i].fd, &exception_set);

        if (fds[i].fd > n)
            n = fds[i].fd;
    };

    if (n == -1)
        /* Hey!? Nothing to poll, in fact!!! */
        return 0;

    if (timeout < 0)
        rc = select(n+1, &read_set, &write_set, &exception_set, NULL);
    else {
        struct timeval    tv;

        tv.tv_sec = timeout / 1000;
        tv.tv_usec = 1000 * (timeout % 1000);
        rc = select(n+1, &read_set, &write_set, &exception_set, &tv);
    };

    if (rc < 0)
        return rc;

    for(i = 0; i < (nfds_t) numfds; i++) {
        fds[i].revents = 0;

        if (FD_ISSET(fds[i].fd, &read_set))      fds[i].revents |= 
POLLIN;
        if (FD_ISSET(fds[i].fd, &write_set))     fds[i].revents |= 
POLLOUT;
        if (FD_ISSET(fds[i].fd, &exception_set)) fds[i].revents |= 
POLLERR;
    };

    return rc;
}

----------
messages: 13677
priority: normal
status: new
substatus: new
title: bug in libavformat/os_support.c poll function under mingw32
type: bug

________________________________________________
FFmpeg issue tracker <[email protected]>
<https://roundup.ffmpeg.org/issue2608>
________________________________________________

Reply via email to