Changeset 909

Show
Ignore:
Timestamp:
03/07/08 11:57:14 (13 years ago)
Author:
ppalmers
Message:

fix port out of range bug

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/devicemanager.cpp

    r898 r909  
    143143    assert(m_busreset_functors.size() == 0); 
    144144 
    145     unsigned int nb_detected_ports = Ieee1394Service::detectNbPorts(); 
     145    int nb_detected_ports = Ieee1394Service::detectNbPorts(); 
     146    if (nb_detected_ports < 0) { 
     147        debugFatal("Failed to detect the number of 1394 adapters. Is the IEEE1394 stack loaded (raw1394)?\n"); 
     148        return false; 
     149    } 
    146150    if (nb_detected_ports == 0) { 
    147         debugFatal("No firewire ports found.\n"); 
     151        debugFatal("No firewire adapters (ports) found.\n"); 
    148152        return false; 
    149153    } 
  • trunk/libffado/src/libieee1394/ieee1394service.cpp

    r904 r909  
    124124} 
    125125 
    126 unsigned int 
    127 Ieee1394Service::detectNbPorts(
     126int 
     127Ieee1394Service::detectNbPorts(
    128128{ 
    129129    raw1394handle_t tmp_handle = raw1394_new_handle(); 
    130130    if ( tmp_handle == NULL ) { 
    131131        debugError("Could not get libraw1394 handle.\n"); 
    132         return 0
     132        return -1
    133133    } 
    134134    struct raw1394_portinfo pinf[IEEE1394SERVICE_MAX_FIREWIRE_PORTS]; 
     
    138138    if (nb_detected_ports < 0) { 
    139139        debugError("Failed to detect number of ports\n"); 
    140         return 0
     140        return -1
    141141    } 
    142142    return nb_detected_ports; 
     
    147147{ 
    148148    using namespace std; 
     149 
     150    int nb_ports = detectNbPorts(); 
     151    if (port + 1 > nb_ports) { 
     152        debugFatal("Requested port (%d) out of range (# ports: %d)\n", port, nb_ports); 
     153    } 
    149154 
    150155    m_handle = raw1394_new_handle_on_port( port ); 
  • trunk/libffado/src/libieee1394/ieee1394service.h

    r864 r909  
    6060    * @return the number of ports 
    6161    */ 
    62     static unsigned int detectNbPorts(); 
     62    static int detectNbPorts(); 
    6363 
    6464   /** 
  • trunk/libffado/tests/test-ieee1394service.cpp

    r881 r909  
    5757 
    5858#define DIFF_CONSIDERED_LARGE (3027/2) 
    59 int PORT_TO_USE = 1
     59int PORT_TO_USE = 0
    6060 
    6161int max_diff=-99999; 
     
    283283    m_service = new Ieee1394Service(); 
    284284    m_service->setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
    285     m_service->initialize(PORT_TO_USE); 
     285    if(!m_service->initialize(PORT_TO_USE)) { 
     286        printf("Could not initialize 1394 service\n"); 
     287        delete m_service; 
     288        exit(-1); 
     289    } 
    286290    m_service->setThreadParameters(true, 60); 
    287291